Call me crazy, but I feel as though I’ve just uncovered the holy grail of Visio.
I don’t know how many people I’ve asked about ways that you can create a Table of Contents in Visio. It seems like it should be sooooo easy, but no one has ever been able to help me out.
So I had a bit of ‘R&D time’ this afternoon and was playing with the Annotation Hiding Macro that Donna posted yesterday, then poked around a few of her other Visio pages, and there, in amongst some comments, I found it! A Macro that creates a Table of Contents in Visio for you.
Hoorah! Celebrations all round!
(Or did you all already know how to do this and I’ve been living under a Visio rock?!)
Now… it’s not all that pretty. But, for now, it does the trick.
Without any further ado, here it is (with many thanks to Bram!):
//
Sub TableOfContents()
‘ creates a shape for each page in the drawing on the first page of the drawing
‘ then add a dbl-clk GoTo to each shape so you can double click and go to that Page
Dim PageObj As Visio.Page
Dim TOCEntry As Visio.Shape
Dim CellOjb As Visio.Cell
Dim PosY As Double
Dim PageCnt As Double
Dim PageNr As Double
‘ ActiveDocument.Pages.Count will give the number of pages, but we are interested
‘ the number of foreground pages
PageCnt = 0
For Each PageObj In ActiveDocument.Pages
If PageObj.Background = False Then PageCnt = PageCnt + 1
Next
‘ loop through all the pages
For Each PageObj In ActiveDocument.Pages
If PageObj.Background = False Then ‘ Only foreground pages
PageNr = PageNr + 1
‘ where to put the entry on the page?
PosY = (PageCnt – PageObj.Index) / 4 + 1
‘ draw a rectangle for each page to hold the text
Set TOCEntry = ActiveDocument.Pages(1).DrawRectangle(1, PosY, 5, PosY + 0.25)
‘ write the page name in the rectangle
TOCEntry.Text = PageObj.Name & vbTab & PageNr
‘ add a link to point to the page to you can just go there with a Double Click
Set CellObj = TOCEntry.CellsSRC(visSectionObject, visRowEvent, visEvtCellDblClick) ‘Start
CellObj.Formula = “GOTOPAGE(“”” + PageObj.Name + “””)”
End If
Next
End Sub
//
Isn’t it beautiful!
Is it just me, or are those interaction designers in The Netherlands particularly clever with Visio?
I like Dan’s TOC better. It is here: http://www.greenonions.com/archives/2005/10/20/stupid-visio-tricks-128-tables-of-contents/
what?! there’s more?
I *have* been under a Visio rock, haven’t I!
I had no idea this was possible, but it’s definitely going to be handy! Thanks.
And I guess you have seen this set of macros: http://www.welie.com/visio/
sure have, thanks!
Anyone else got any excellent Visio macros they’d like to share? :)
hey. on a totally different matter (just stumbled in here). have you any idea of how you would go about making a macro that allowed “mouseover” effects.. which showed a layer with an image and text in (basicaly just like in html) ?
cheers
lars
hey Lars,
Do you want Visio to actually react to the mouse ‘mousing over’ a location on your Visio wireframe? Because I’ve not heard of anyone being able to wrangle VISIO to that extent… you’re going to want to build a bit of a prototype in HTML with some JavaScript to show this kind of interaction.
Of course, you can show mouse over and other states on different layers and reveal and hide layers depending on states… I don’t think that’s necessarily the best way to show the design of states, but depends on what works for you I guess.
does that go anywhere near answering your question? :)