I demonstrated how to import hyperlinks into Visio shapes in a previous post – see http://blog.bvisual.net/2007/11/15/importing-hyperlinks-into-visio-shapes/, however, one of my readers wanted to know if the same mechanism can be used to create an hyperlink to another page in the same Visio document, rather than to an external web page. Well, it can be done … with a little preparation.
The Link Data to Shapes feature will by default only create external links because it pushes values from designated Shape Data fields into Hyperlink rows. You can designate Shape Data columns by ticking the Data Type / Hyperlink checkbox:
In my example, I have put the values Page-1 or Page-2 in the Link column, and set this Data Type as String Hyperlink, and this sets an Hyperlink with an Address Page-1 or Page-2. However, other pages, and shapes, are entered into the Sub-address property, but Visio prevents you from setting this if there is anything in the Address property.
So, the challenge is push the Address values into the Sub-address automatically.
Fortunately, the name of the Hyperlink row is predictable because it is named according to the Label of the Shape Data row, with a prefix _VisDM_. Therefore, the Link Shape Data row will create an Hyperlink row named Hyperlink._VisDM_Link. Knowing this, you can prepare a Master shape to be linked to the data with some ShapeSheet formulas.
The first action is to create the named Hyperlink row in the master shape. Then I created two User-defined cells with some ShapeSheet formulas in them.
The first User-defined cell is called LinkTrigger, and this contains the formula to move the Address to the Sub-address cell, if the Address does not start with http :
=DEPENDSON(Hyperlink._VisDM_Link.Address,Hyperlink._VisDM_Link.SubAddress)+IF(AND(NOT(STRSAME(LEFT(Hyperlink._VisDM_Link.Address,4),”http”,TRUE)),LEN(Hyperlink._VisDM_Link.Address)>0),SETF(GetRef(Hyperlink._VisDM_Link.SubAddress),”=”””&Hyperlink._VisDM_Link.Address&””””)+SETF(GetRef(Hyperlink._VisDM_Link.Address),”=”””””),IF(LEN(Hyperlink._VisDM_Link.Address)>0,SETF(GetRef(Hyperlink._VisDM_Link.SubAddress),”=”””””),0))
The second User-defined cell is called LinkInvisibleTrigger, and this is required to reset the Invisible cell formula because the Link Data to Shapes feature will put the formula =LEN(Hyperlink._VisDM_Link.Address)=0 into that cell, and this will hide your carefully constructed Sub-address hyperlink:
=DEPENDSON(Hyperlink._VisDM_Link.Invisible)+SETF(GetRef(Hyperlink._VisDM_Link.Invisible),”=GUARD(AND(LEN(Hyperlink._VisDM_Link.Address)=0,LEN(Hyperlink._VisDM_Link.SubAddress)=0))”)
These two User-defined cell formulas will ensure that the data-linked shape will get an hyperlink to another page in the document (provided that you have entered a valid page name!).
You should be aware that the hyperlinks will not get automatically updated if you change the names of the pages. You should go back to your data source and update the values there before refreshing the shapes from it.
The hyperlink will be available from the right-mouse menu of each shape:
As an optional extra, you could use the following formula in User.LinkTrigger value cell if you want to also modify the Double-Click event of the shape to automatically go to the page:
=DEPENDSON(Hyperlink._VisDM_Link.Address,Hyperlink._VisDM_Link.SubAddress)+IF(AND(NOT(STRSAME(LEFT(Hyperlink._VisDM_Link.Address,4),”http”,TRUE)),LEN(Hyperlink._VisDM_Link.Address)>0),SETF(GetRef(Hyperlink._VisDM_Link.SubAddress),”=”””&Hyperlink._VisDM_Link.Address&””””)+SETF(GetRef(Hyperlink._VisDM_Link.Address),”=”””””)+SETF(GetRef(EventDblClick),”=GOTOPAGE(“””&Hyperlink._VisDM_Link.Address&”””)”),IF(LEN(Hyperlink._VisDM_Link.Address)>0,SETF(GetRef(Hyperlink._VisDM_Link.SubAddress),”=”””””),0))
QED.
shawnhishere says
This worked beautifully – for some reasone the double click code isn’t working though.
DEPENDSON(Hyperlink._VisDM_Link.Address,Hyperlink._VisDM_Link.SubAddress)+IF(AND(NOT(STRSAME(LEFT(Hyperlink._VisDM_Link.Address,4),”http”,TRUE)),LEN(Hyperlink._VisDM_Link.Address)>0),SETF(GetRef(Hyperlink._VisDM_Link.SubAddress),”=”””&Hyperlink._VisDM_Link.Address&””””)+SETF(GetRef(Hyperlink._VisDM_Link.Address),”=”””””)+SETF(GetRef(EventDblClick),”=GOTOPAGE(“””&Hyperlink._VisDM_Link.Address&”””)”),IF(LEN(Hyperlink._VisDM_Link.Address)>0,SETF(GetRef(Hyperlink._VisDM_Link.SubAddress),”=”””””),0))
Please advise what’s wrong.
davidjpp says
I think that WordPress has displayed incompatible double-quotes … try replacing all of the double-quotes with the one in Visio.
shawnhishere says
I was able to get the code to take, however, I double click and nothing happens. Am I supposed to put this same formula in the EventDblClick tab? if not, what am I supposed to put in that tab?
Paul Hofmann says
I am attempting this in Visio Pro 2013, but get “Error in formula.” when attempting to save either the LinkTrigger orLinkInvisibleTrigger formulas.
Paul Hofmann says
An alternative, working for me in Visio Pro 2013, is to specify the page link as “MyDiagram#MyPage” along with setting the Data Type as String Hyperlink. That value goes into the Address field, and there is no need to move it to Sub-address.
Dian Ledbetter says
I have been trying to get the 2 options presented to work, but I am having no luck.
If the MyDiagram name has spaces, will that break that simpler option?
If I need to use the ShapeSheet formulas, where do I put those? It looks like it would be in my Excel sheet but I don’t have those options anywhere that I can find.
Note I need this work when I make the Visio into a pdf as well. Help, please!
David Parker says
Hi! The formulas have to be added to the User-defined Cells section of the ShapeSheet of the master. I have edited the Department and Person masters in this document to demonstrate : Intra Document Links.vsdx