Newbie Help with Counting and Numbering Shapes

Started by JeanK, November 09, 2017, 05:01:52 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

JeanK

Hi all,

I am brand new to Visio Macros, I have had some experience in Excel but I am struggling to get a start in Visio.

Basically, I am trying to create a macro that will number shapes automatically and I would be able to re-run it if I add/remove shapes.

Also I would like to append some text based on a set field E.G Procedure_#

So to start with I am trying to do something simple and count the number of shapes on screen

I am a bit confused I have looked up this reference here...however it seems to be counting documents?

https://msdn.microsoft.com/en-us/vba/visio-vba/articles/shapes-count-property-visio

Also I have found a snippet of code to try however I am unsuccesfull.

Sub Counter()

Dim shp As Visio.Shape
Dim i As Integer

For Each shp In ActivePage.Shapes
   If shp.Master<>Nothing Then
        i = i + 1
      End If
      ActivePage.Shapes("SheetED").Characters.Text = CStr(i)
   End If
Next shp

Debug.Print i
End Sub

Paul Herber

Does the built-in shape number not do what you want?
View -> Addons -> Visio Extras -> Number shapes
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

JeanK

Thanks, I have looked into that, unfortunately no, as I want to append its text to show for exxample Procedure_1

Unless theres a way to specify where the numbering goes?

Yacine

#3
1)
Quote from: JeanK on November 09, 2017, 05:01:52 AM
... however I am unsuccesfull. ...

What is the problem with your code?

2)
You can number the shapes directly by assigning i to a "number" field (eg prop.number)

Sub Number()

Dim shp As Visio.Shape
Dim i As Integer

For Each shp In ActivePage.Shapes
   If shp.Master<>Nothing Then
        i = i + 1
        if shp.cellexistsu("prop.number",false) then
            shp.cells("prop.number").formulau = i
        end if
      End If
   End If
Next shp

End Sub



and you can insert this field in the shape to be displayed. (https://support.office.com/en-us/article/Insert-a-text-field-into-a-shape-0225c22e-3e5e-4ea7-9ca0-1ec91386cb1e)
Yacine

Paul Herber

Quote from: JeanK on November 09, 2017, 08:47:09 PM
Thanks, I have looked into that, unfortunately no, as I want to append its text to show for exxample Procedure_1

Unless theres a way to specify where the numbering goes?

Yes, have as look on the Advanced tab of the Shape number dialog.
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

JeanK

Excellent!!@!@

Yes the advanced shape parramaters help me achieved this, sorry I didn' look hard enough!

Also thanks for the code, I was interested in doing this programatically too!

Thanks all!