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

image

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.

image

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.

image

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!).

image

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:

image

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.

5 Responses to “Creating Shape to Page Hyperlinks Automatically using Link Data to Shapes”

  1. 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.

  2. 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?

  3. 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.

  4. 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.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Chris Webb's BI Blog

Microsoft Analysis Services, MDX, DAX, Power Pivot, Power Query and Power BI

davecra.wordpress.com/

Microsoft Office 365 Development, and more...

PowerShell.Amsterdam

Automate, Accelerate, Accurate

johnvisiomvp

Life with Visio and other Microsoft Toys!

Title (Required)

Windows Server Essentials Tips & Tricks

Nilsandrey's Weblog

Just another WordPress.com weblog

Things that Should be Easy

Every so often (too often in the IT industry) I encounter things that should have been very easy to do but turned out to be far too complicated. My favorite topics include SharePoint, .Net development, and software architecture, especially distributed systems.

Visio Guy

Shapes, Stencils, Drawings Templates, Tutorials, Tips & Developer Info for Microsoft Visio

Hannes's Virtual Earth

Tips & Tricks around Mapping and Cloud Computing

Pluralsight blog

be smart, be clear, be visual ...

%d bloggers like this: