Reading and Editing User-Defined Block Icon Attributes via VBA in WinCC Graphics Designer
Attempting to read user-defined attributes such as 'TagNameDisplayed' using 'objObject.TagNameDisplayed' in WinCC Graphics Designer VBA produces runtime error 438 ('Object doesn't support this property or method') because 'TagNameDisplayed' is not a native COM property of 'HMIObject'. To correctly read and modify user-defined or dynamic properties in VBA, access the object's 'Properties' collection using the syntax 'objObject.Properties("TagNameDisplayed").Value'. This allows automated batch auditing and renaming of APL block icon labels across all process displays.
Table of Contents
- Executive Summary
- Architectural and System Mechanics
- Step-by-Step Engineering and Implementation Procedure
- Verification
- Limitations and Operational Precautions
- Engineer FAQ
- Technical References
- Related Articles
- Related Tags
Executive Summary
During large-scale PCS 7 commissioning or plant standardization projects, automation engineers frequently write Visual Basic for Applications (VBA) macros inside WinCC Graphics Designer to automate repetitive tasks, such as renaming tags or updating display labels on hundreds of block icons. However, developers attempting to read customized APL properties—such as TagNameDisplayed—often hit a programming roadblock: the standard VBA object accessor throws Error 438: Object doesn't support this property or method. This article explains the internal object model of WinCC Graphics Designer, contrasts native COM properties with dynamic property collections, and provides production-ready VBA scripts to batch-edit block icon attributes.
Architectural and System Mechanics
WinCC Graphics Designer Object Model Architecture:
HMIObjectInterface: Represents any graphical element (rectangle, circle, customized block icon, OLE control) placed on a.pdlpicture screen.- Native Properties vs. Dynamic Property Collection:
- Native Properties: Directly exposed via COM interface methods (e.g.,
objObject.ObjectName,objObject.Layer,objObject.Width,objObject.Height,objObject.Type). - Dynamic / User-Defined Properties: Custom attributes added to grouped or customized objects (such as
TagNameDisplayed,ServerName,Type,HighlightColor) do NOT exist as direct COM methods. Instead, they reside in theobjObject.Propertiescollection. - Correct Access Syntax:
objObject.Properties("TagNameDisplayed").Value. - Error 438 Mechanism: Calling
objObject.TagNameDisplayedforces VBA to query the early-bound COM dispatch table ofHMIObject, which lacks this member, throwing Error 438 immediately.
Step-by-Step Engineering and Implementation Procedure
Step 1: Open the VBA Editor in Graphics Designer
- Open any process display picture in WinCC Graphics Designer.
- Press
Alt + F11to launch the integrated Microsoft Visual Basic for Applications (VBA) editor. - Insert a new module under
VBA-Project (<PictureName>.pdl)-> 'Modules' -> 'Module1'.
Step 2: Implement the Safe Attribute Reader Macro
Write a VBA routine that iterates through all objects on the screen, checks for the existence of TagNameDisplayed, and reads its value:
Sub ReadAllTagNamesDisplayed()
Dim objObject As HMIObject
Dim objProp As HMIProperty
Dim strTag As String
For Each objObject In ActiveDocument.HMIObjects
On Error Resume Next
Set objProp = objObject.Properties("TagNameDisplayed")
On Error GoTo 0
If Not objProp Is Nothing Then
strTag = objProp.Value
Debug.Print "Object: " & objObject.ObjectName & " | TagNameDisplayed: " & strTag
Set objProp = Nothing
End If
Next objObject
End Sub
Step 3: Implement Batch Attribute Modification Script
To batch-modify prefixes or strip chart names across all icons on the screen:
Sub BatchModifyTagNameDisplayed()
Dim objObject As HMIObject
Dim objProp As HMIProperty
For Each objObject In ActiveDocument.HMIObjects
On Error Resume Next
Set objProp = objObject.Properties("TagNameDisplayed")
On Error GoTo 0
If Not objProp Is Nothing Then
' Example: Replace prefix "OLD_" with "NEW_"
If InStr(objProp.Value, "OLD_") > 0 Then
objProp.Value = Replace(objProp.Value, "OLD_", "NEW_")
End If
Set objProp = Nothing
End If
Next objObject
ActiveDocument.Save
End Sub
Step 4: Execute Macro and Review Output
Run the macro via F5 in the VBA editor. Inspect the Immediate Window (Ctrl + G) to verify all parsed tags.
Verification
To verify macro execution:
1. Check the Immediate Window in the VBA editor; confirm that all block icons report their custom display strings without throwing Error 438.
2. Switch to Graphics Designer; select a modified block icon and inspect its Object Properties window under 'System' -> 'TagNameDisplayed'.
3. Confirm that the text field reflects the script's updated string.
4. Save the picture and verify display appearance in WinCC Graphics Runtime.
Limitations and Operational Precautions
Operational precautions:
- Modifying TagNameDisplayed alters only the text label shown on screen; it does NOT alter the underlying runtime connection tag (Tag), leaving process communication unaffected.
- Always create a backup of the .pdl picture file before executing batch modification macros.
- Rerunning 'Create/Update Block Icons' in SIMATIC Manager will overwrite custom TagNameDisplayed values unless block icon rules in the Plant Hierarchy are synchronized.
Engineer FAQ
Q: Why did objObject.TagNameDisplayed trigger Error 438?
A: Because TagNameDisplayed is a user-defined property stored within the Properties collection, not a direct COM method of HMIObject.
Q: Can this VBA script run in WinCC Runtime?
A: No. VBA macros execute inside Graphics Designer during engineering. For runtime actions, use C-Script or VBScript (using ScreenItems("Object").TagNameDisplayed).
Q: How do I check if an object possesses a specific property?
A: Use On Error Resume Next, attempt to set objProp = objObject.Properties("PropertyName"), and check If Not objProp Is Nothing.
Q: Can VBA edit properties across multiple .pdl files automatically?
A: Yes, by utilizing Documents.Open within a VBA loop over all files in the GraCS directory.
Q: Does changing this property modify CFC block comments?
A: No. VBA edits the WinCC graphic display properties only; controller CFC configurations are unchanged.
Technical References
- SIMATIC WinCC V7.5 SP2 Script: C, VBS, VBA
- SIMATIC Process Control System PCS 7 Advanced Process Library (APL) Styleguide
- PCS 7 V9.0 SP3 Licenses and Configuration Limits
Related Articles
- Customizing APL Block Icon Tag Name Formats and Stripping Hierarchy Prefixes in WinCC
- Creating Custom APL-Style Faceplate Popups and Block Icons in SIMATIC PCS 7 WinCC
- Resolving AxRulerControl Sizing and Width Limit Clamping in WinCC Trend Displays
Related Tags
WinCC VBA, TagNameDisplayed, HMIObject, Error 438, Graphics Designer