Author Topic: Newbie Help with Counting and Numbering Shapes  (Read 194 times)

0 Members and 1 Guest are viewing this topic.

JeanK

  • Newbie
  • *
  • Posts: 3
Newbie Help with Counting and Numbering Shapes
« on: November 09, 2017, 12:01:52 AM »
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

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2501
    • Paul Herber's website
Re: Newbie Help with Counting and Numbering Shapes
« Reply #1 on: November 09, 2017, 04:10:07 AM »
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 and applications for Visio - http://www.paulherber.co.uk/
Facebook: https://www.facebook.com/Paul-Herbers-Software-Products-422546858110438/

JeanK

  • Newbie
  • *
  • Posts: 3
Re: Newbie Help with Counting and Numbering Shapes
« Reply #2 on: November 09, 2017, 03: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?

Yacine

  • Hero Member
  • *****
  • Posts: 2323
Re: Newbie Help with Counting and Numbering Shapes
« Reply #3 on: November 10, 2017, 02:44:54 AM »
1)
... 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)

Code: [Select]
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)
« Last Edit: November 10, 2017, 02:48:11 AM by Yacine »
Yacine

Paul Herber

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2501
    • Paul Herber's website
Re: Newbie Help with Counting and Numbering Shapes
« Reply #4 on: November 11, 2017, 06:42:38 AM »
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 and applications for Visio - http://www.paulherber.co.uk/
Facebook: https://www.facebook.com/Paul-Herbers-Software-Products-422546858110438/

JeanK

  • Newbie
  • *
  • Posts: 3
Re: Newbie Help with Counting and Numbering Shapes
« Reply #5 on: November 12, 2017, 06:21:00 PM »
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!