Create shape name with function/macro

Started by breital, February 06, 2018, 07:02:04 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

breital

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!

Surrogate

#1
Hi !

what you mean as linked page ? Hyperlink sub-address to some page ?

breital

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 :/

Surrogate

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