Visio VBA Hyperlinks

G

Grind63

Anyone familiar with how to edit hyperlinks for multiple shapes by VBA. I
have a series of VSD files that have numerous shapes and pages. Due to soem
changes the code generated hyperlinks created for each shape in these files
is missing a prefix to ensure the file will open a link properly on our
website. For exmaple the current link for one shape is jump.htm?project=1,
and it needs to be revised to ../../../Test/jump.htm?project=1. The only
portion of the hyperlink that is common is the jump.htm, so I am looking for
a VBA code/macr I can run on each file or on a directory of files to revise
every hyperlink for every shape on every file. I have tried several things
with no louck. ANy help would be greatly appreciated. Thanks.
 
A

AlEdlund

I'd suggest that you take advantage of the macro recorder while performing
your fixes on the hyperlink section of the shapesheet.
al
 
P

Paul Herber

Anyone familiar with how to edit hyperlinks for multiple shapes by VBA. I
have a series of VSD files that have numerous shapes and pages. Due to soem
changes the code generated hyperlinks created for each shape in these files
is missing a prefix to ensure the file will open a link properly on our
website. For exmaple the current link for one shape is jump.htm?project=1,
and it needs to be revised to ../../../Test/jump.htm?project=1. The only
portion of the hyperlink that is common is the jump.htm, so I am looking for
a VBA code/macr I can run on each file or on a directory of files to revise
every hyperlink for every shape on every file. I have tried several things
with no louck. ANy help would be greatly appreciated. Thanks.

If it's for every hyperlink then it might be possible to do this:
menu File -> Properties
and set the Hyperlink base to "../../../Test/"
 
G

Grind63

AlEdlund,

Tried that, but it does not record correctly and requires the shapes to be
selected oen by one. Was hopign for somethign to loop through each shape and
make the corrections, but I cannot figure out the correct VBA code sequence
to do it. Thanks.
 
G

Grind63

Paul,

Tried that first thing. It will not accept the string as entered. However,
if I change it in the cell directly it works like a charm. Very frustrating.
Thanks.
 
A

AlEdlund

So you wrap the hyperlink (shape sheet cell) manipulation with a loop
something like

dim visShape as visio.shape
dim visShapes as visio.shapes
dim visPage as visio.page
set visPage = application.activepage
set visShapes = visPage.Shapes
for each visShape in visShapes
' do the hyperlink cell modification
next visShape

al
 
G

Grind63

AlEdlund,

I will give that a try. Thanks.

AlEdlund said:
So you wrap the hyperlink (shape sheet cell) manipulation with a loop
something like

dim visShape as visio.shape
dim visShapes as visio.shapes
dim visPage as visio.page
set visPage = application.activepage
set visShapes = visPage.Shapes
for each visShape in visShapes
' do the hyperlink cell modification
next visShape

al
 
G

Grind63

AlEdlund,

Okay tried to your suggestion, but I believe the issues I am having is with
how the record macro sets the focus. The following is the portion that
starts the revision of the hyperlink by the record macro method:

Dim vsoHlink1 As Visio.Hyperlink
Set vsoHlink1 =
Application.ActiveWindow.Page.Shapes.ItemFromID(682).Hyperlinks.Item(0)

As you see it is selecting a single shape in the set vsoHlink definition,
which I am not sure how to revise to allow the looping function you sent.
Any suggestions? Thanks.
 
S

SteveM

AlEdlund,

Okay tried to your suggestion, but I believe the issues I am having is with
how the record macro sets the focus.  The following is the portion that
starts the revision of the hyperlink by the record macro method:

    Dim vsoHlink1 As Visio.Hyperlink
    Set vsoHlink1 =
Application.ActiveWindow.Page.Shapes.ItemFromID(682).Hyperlinks.Item(0)

As you see it is selecting a single shape in the set vsoHlink definition,
which I am not sure how to revise to allow the looping function you sent. 
Any suggestions?  Thanks.

Ya gotta follow Al's code. The For Each loop sets the focus through
all the shapes on the page.

If you want to amend existing hyperlink names, try this:

dim visShape as visio.shape
dim visShapes as visio.shapes
dim visPage as visio.page
dim linkName as Variant
set visPage = application.activepage
set visShapes = visPage.Shapes
for each visShape in visShapes
linkName = visShape.Hyperlinks.Item(0).Address
linkName = "new prefix" & linkName
visShape.Hyperlinks.Item(0).Delete
visShape.Hyperlinks.Add.Address = linkName
next visShape

Above assumes you only have one hyperlink per shape. You also may
have shapes on the page without hyperlinks. In those cases, you have
to insert logic to select the correct link and/or bypass shapes
without links.

SteveM
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top