Author Topic: Change a shapes colour when selected from a hyperlink  (Read 899 times)

0 Members and 1 Guest are viewing this topic.


  • Newbie
  • *
  • Posts: 1
Change a shapes colour when selected from a hyperlink
« on: June 21, 2019, 09:46:29 AM »
Hi folks

N00b to VBA in Visio, I'm ok with Excel but just starting out with Visio.
Apologies if this has been asked before, I've used search and can't find anything to match my query.

Anyhoo... I have a Visio process map that has 5 tabs/pages. On the main page "Hire And Approvals" I have hyperlinked some shapes to go to other pages depending on what the selection for the process is. However, on those subsequent pages there are also a number of shapes depending on what is happening in the process. Some are also hyperlinks and some are just part of the flow in process.
So what I was hoping would be possible is when someone selects the hyperlink to follow the process and it moves to the correct department page the shape would highlight somehow instead of just being centred. If it could change the colour for 3 seconds or so that would be marvellous.

Does anyone know how I could achieve this please? Even if it just changes the colour while they are on that page instead of being timed that would be great if having it timed is not possible.

Thanks in advance  :)

Thomas Winkel

  • Full Member
  • ***
  • Posts: 194
Re: Change a shapes colour when selected from a hyperlink
« Reply #1 on: November 19, 2019, 02:03:00 PM »

this is possible with VBA, see attached document.
The following formula in ShapeSheet Cell "EventDblClick" calls the VBA code:

Sub JumpToLinkedShape(shp As Visio.Shape)
    Dim PageName As String
    Dim ShapeName As String
    Dim LinkedShape As Visio.Shape
    PageName = Split(shp.Cells("Hyperlink.Row_1.SubAddress").ResultStr(visNone), "/")(0)
    ShapeName = Split(shp.Cells("Hyperlink.Row_1.SubAddress").ResultStr(visNone), "/")(1)
    Set LinkedShape = ActiveDocument.Pages(PageName).Shapes.Item(ShapeName)
    ActiveWindow.CenterViewOnShape LinkedShape, visCenterViewSelectShape
'    ' Probably not required
'    Dim t As Single
'    Dim pause As Single
'    Dim colorBackup As Integer
'    colorBackup = LinkedShape.Cells("FillForegnd")
'    LinkedShape.Cells("FillForegnd").Formula = 2
'    pause = 2
'    t = Timer
'    Do While Timer < t + pause
'        DoEvents
'    Loop
'    LinkedShape.Cells("FillForegnd").Formula = colorBackup
End Sub

The target shape will be centered and selected.
Also color highlighting is possible, just uncomment the lines in VBA code.
Target is the same as hyperlink.