Visio Guy

Visio Discussions => Shapes & Templates => Topic started by: breital on February 06, 2018, 07:02:04 AM

Title: Create shape name with function/macro
Post by: breital on February 06, 2018, 07:02:04 AM
HEY guys,

I'd like to name a shape (in developer ribbon) with an individual letter combination and the number of the page it is linked to.

So e.g.: if the shape is linked to another shape at page 30 of foregrounds, its name should be A30.
Need your brains  :D
I don't know enough vba codes or orders to get the solution by myself  :-[

Hope it is easier for you!
Title: Re: Create shape name with function/macro
Post by: Surrogate on February 06, 2018, 07:09:43 AM
Hi !

what you mean as linked page ? Hyperlink sub-address to some page ?
Title: Re: Create shape name with function/macro
Post by: breital on February 14, 2018, 09:47:49 AM
Hello Surrogate,

yes, exactly. A hyperlink with subadress to another page :)
I'm sure this must be possible anyway, but don't have the experience in VBA with Visio :/
Title: Re: Create shape name with function/macro
Post by: Surrogate on February 14, 2018, 01:43:00 PM
Please try this code !
Sub For_Breital()
Dim shp As Shape, sa As String, dp As Integer
For Each shp In ActivePage.Shapes
' check is shape have hyperlinks
If shp.SectionExists(visSectionHyperlink, visExistsAnywhere) Then
' check is shape's hyperlink have sub-address
    If Len(shp.Hyperlinks(0).SubAddress) > 0 Then
' check is sub-address have shape's name
        If InStr(shp.Hyperlinks(0).SubAddress, "/") > 0 Then
' split pagename in sub-address
            sa = Left(shp.Hyperlinks(0).SubAddress, InStr(shp.Hyperlinks(0).SubAddress, "/") - 1)
        Else
            sa = shp.Hyperlinks(0).SubAddress
        End If
' rename shape
    shp.Name = sa
    End If
End If
Next
End Sub