johnvisiomvp

Life with Visio and other Microsoft Toys!

Posts Tagged ‘Masters

Friendly Visio Stencil

with 2 comments

I am working with a stencil that contains almost 400 shapes and it is far from friendly. Normally a new stencil will show the icon for the shape and its’ name. With this project, the name is far from helpful. Undecypherable is more appropriate. If you right click the band at the top of the stencil window, you are given a choice for View of Icons and Names, Names Under ICons, Icons Only, Names Only and  Icons and Details. The last looks tempting, but there is no such cell as Details. What it is, is … Icons & Names over a prompt.
stencil2
Luckily there is something in the master called prompt. Now, of course, populating that field for almost 400 masters is not trivial, or is it? Back in the days of Visio 3.0, Visio was the first non Microsoft company to fully implement VBA, including the macro recorder. So, it should just be a matter of a few lines of VBA code. It does help if the shape does contain some text that can be used. In this case, I have a Shape Data field called Description that contains the necessary text.

Public Sub EditMaster()
Dim vsoMaster As Visio.Master
Dim vsoCell As Visio.Cell
Dim vsoShapes As Visio.Shapes
Dim vsoShape As Visio.Shape

For Each vsoMaster In ActiveDocument.Masters
If vsoMaster.Shapes(1).CellExists(“Prop.Description”, 0) Then
Set vsoCell = vsoMaster.Shapes(1).Cells(“Prop.Description”)
vsoMaster.Prompt=
Replace(Replace(vsoCell.ResultStr(Visio.visNone), “””, “IN”), “&”, “&”)
End If
Next vsoMaster
End Sub

A few things to note;
– The original text for the field came from XML, so there is a little playing to handle the abbreviation for inches and the ampersand. Luckily I did not have to deal with feet. 😉
– Only masters that have a shape data of Description are changed, all others are left alone.
– for those familiar to using VBA with masters, you do NOT need to wrap the code with an Open / Close that is required when modifying other fields in a master.
Enjoy…

John Marshall… Visio MVP Visio.MVPs.org

Advertisements

Written by johnvisiomvp

October 9, 2016 at 4:52 pm

Posted in Shapes, VBA, Visio

Tagged with , ,