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.
… that is the question! I have known for some time that it is safer to copy and paste code from the web into Notepad or similar, before copying and pasting that into my own code. It is not only new line characters that can be different but also the double-quotes. I recently noticed this…
Developing a Visio solution usually involves both .Net code and Visio ShapeSheet formulas. Good practice dictates that the source code is saved into a code repository, such as Git, where changes can be committed and commented. Visual Studio 2019 now includes native Git support, and can be linked to Azure DevOps easily. The code can…
The second 32 of the Visio ShapeSheet functions that start with the letters D through to F 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. Each of the ShapeSheet functions that start with the letters…
The first 36 of the Visio ShapeSheet functions that start with the letters A through to C 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…)
Visio was the first non-Microsoft application to include VBA within it back in the mid-nineties. All of the desktop Microsoft Office applications currently include VBA, although Microsoft have been rumoured to want to replace it for many years, and now there is an alternative scripting option becoming available that is suitable for the web too.…
Still in lockdown on holiday, so I thought I would create a version of backgammon that can be played with Visio for the web. This was inspired by my original Visio tutor, the late David Edson, who created a Visio backgammon document which included macros. Macros are not available in Visio for the web, so…