Link to home
Start Free TrialLog in
Avatar of Bladey001
Bladey001Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Changing all the hyperlinks in a Visio document

Hi all

I need to change all the hyperlinks in a visio document from "C:\Documents and Settings\...." to "\\server1\..."

I know for Excel you can create a macro to do this - if that will work in Visio can somebody give me the macro... or if theres any other quick way of doing this.

Thanks in advance
ASKER CERTIFIED SOLUTION
Avatar of Scott Helmers
Scott Helmers
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bladey001

ASKER

Worked like a treat. Thanks Scott!
I'm glad the code I posted last night did the trick. I borrowed the middle part that actually does the text replacement from something else but it's been bothering me that it looked so complex. So I've posted the much simpler version below.

BTW, if you know in advance you'll be moving the targets of the hyperlinks, you can avoid the need for a macro altogether by using the Hyperlink Base field in a Visio document.

Save your document, then when you create the links, uncheck the box that says "Use relative path for hyperlink". At this point, the "hyperlink base", i.e., the starting point for following hyperlinks, is the folder in which the Visio drawing resides. But you can change it to another location by selecting File/Properties and typing something into the Hyperlink Base field toward the bottom of the dialog.

In your example, the base would previously have been set to "C:\Documents and Settings\". If you move the docs, then change the base to "\\server1\" you would be all set.

You may need to experiment with this a bit to get it to behave exactly the way you want, including possibly setting the hyperlink base before you create the links, but it should give you more flexibility.
Sub ChangeHyperlinks()
' change all hyperlinks on all shapes on all pages that start with
' "C:\Documents and Settings\" to start with "\\server1\"
 
    Dim pg As Page
    Dim shp As Shape
    Dim hl As Hyperlink
    
    For Each pg In ActiveDocument.Pages
        For Each shp In pg.Shapes
            For Each hl In shp.Hyperlinks
                hl.Address = Replace(hl.Address, "C:\Documents and Settings\", "\\server1\")
            Next
        Next
    Next
 
End Sub

Open in new window