Create a shape with specific name if it is missing?

Started by VisDom, September 05, 2017, 02:02:36 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

VisDom

Hi all,

I am fairly new to Visio but quite tech savy. I want to create a peace of code that runs every time I open my visio file and checks if a shape named "SpecialShape" is present on the first page. If not (bacause someone else have deleted it) I want the script to create it.

I figured out how to create a shape with a special name "NameU". My main question is: How to check if the shame with the Name "SpecialShape" is always present on the first page when I open up my document?

Private Sub Button1_Click()

    Dim vsoShape1 As Visio.Shape
    Dim vsoShape2 As Visio.Shape
 
    Set vsoShape1 = ActivePage.DrawRectangle(0, 0.2, 2, 0)
    vsoShape1.TextStyle = "Normal"
    vsoShape1.NameU = "SpecialShape"
    vsoShape1.LineStyle = "Text Only"
    vsoShape1.FillStyle = "Text Only"
    vsoShape1.Text = "Just a text"   
End Sub


Any ideas?

wapperdude

#1
Visio 2019 Pro

VisDom

That helps. Thanks!

How would I check if a shape with the Name  "SpecialShape" exists? I only find examples to identify shapes by ID?

VisDom

ok, found this solution:

For Each shp In ActivePage.Shapes
      If shp.Name = "SpecialShape" Then: Exit Sub
Next