Site icon bVisual

Creating Shape to Page Hyperlinks Automatically using Link Data to Shapes

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.

Exit mobile version