Every Visio shape must have a unique name in the collection that it belongs to, and to ensure this, Visio automatically one using the master name or just “Sheet”, if not an instance of a master, followed by a period (“.”) and the ID. However, a user can rename a shape, and Visio will then also update the universal name (NameU) to be the same as the Name. If a user chooses to re-name a shape a second time, then thee universal name is not updated … it remains as the original name.
To demonstrate this I drew a rectangle, then named, and re-named it:
This is the simple VBA code that was called by an Action in the shape:
Public Sub ShapeNames(ByRef shape As Visio.shape) Dim txt As String txt = "ID = " & shape.ID txt = txt & vbCrLf & "Name = " & shape.Name txt = txt & vbCrLf & "NameID = " & shape.NameID txt = txt & vbCrLf & "NameU = " & shape.NameU MsgBox txt End Sub
So, there can be several ways to reference a shape, but be aware when they can be used. For example, the Name cannot be directly typed into a ShapeSheet formula, but the NameU can.
If the NameID is used in a ShapeSheet formula, then it will be automatically re0displayed with the NameU.
Interestingly, either the NameID, NameU or Name can be used if using the EVALTEXT(…) function is used.
In VBA, or other code, then the shape can be referenced by either the NameID or Name, but not by the NameU value. The shape can also be referenced with ID value using the ItemFromID function.
?ActivePage.Shapes("Sheet.1").NameU Shape A ?ActivePage.Shapes("Shape B").NameU Shape A ?ActivePage.Shapes.ItemFromID(1).NameU Shape A
If the Name is deleted using the Shape Name dialog, then the Name is reverted to the NameID, but the NameU still remains unchanged.
The universal name, NameU, was created so that the Visio UI could display a language specific Name value whilst maintaining a language independent NameU in the background.
Code can be used to update the NameU, provided that it is a unique name within the collection.
My good friend Scott Helmers, Visio author and trainer, of Harvard Computing Group , recently asked for some help in keeping data graphic items level when their target shape is rotated. Fortunately, I was able to assist, so I thought I would explain how this can be done, and also update my Icon Maker macro…
The seventh, and final, 25 of the Visio ShapeSheet functions that start with the letters T – Z are visually described in the Visio document below that is available for download. Please see the general introduction to this series at ShapeSheet Functions A-Z for more information. (more…)
Many years ago, I wrote some VBA code to calculate the length of a multi-segment line in Visio, see Automating Area and Perimeter Length Shape Data , but Microsoft have since provided a handy ShapeSheet function, PATHLENGTH(…), to do the same without any VBA. The function is described on one of the pages in Visio…
The sixth 19 of the Visio ShapeSheet functions that start with the letter S are visually described in the Visio document below that is available for download. Please see the general introduction to this series at ShapeSheet Functions A-Z for more information. (more…)
There are times that I have been caught out by assuming that everyone speaks “proper” English, like what I do (sic), and forgetting that there are other languages with their own formatting conventions. I think most of the world is bemused at the USA date format where they put the month before the day and…
The fifth 33 of the Visio ShapeSheet functions that start with the letters O through to R are visually described in the Visio document below that is available for download. Please see the general introduction to this series at ShapeSheet Functions A-Z for more information. (more…)