Inserting a block of text that displays a table of contents

D

demo

I would like to automate a table of contents that would insert a list of the
tabs that the drawing contains. I would like to include numbers next to
these: (ie:

1 - Cover Page
2 - Page 2
3 - Page 3
Etc...

Thanks, Derek
 
D

demo

I did find a specific example for "Table of Contents" on his site. It works
but needs some heavy tweeking. I would like to know how I can align the text
in the cells, format the lines, change the font, add page numbers, etc... I
also played with the numbers and was unable to change the alignment on the
page as far as listing the TOC on the page from the top down as opposed to
bottom up.

Is there an easy description of properties, events and methods that makes
sense? I am really unable to make heads or tails of the "Developing Microsoft
Visio Solutions" Developer manual. I am using Excel and Access in conjunction
with Visio.

Thanks in advance.

Derek

PS: Here is my code if you need it.

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 CellObj As Visio.Cell
Dim PosY As Double
Dim PageCnt 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

' where to put the entry on the page?
'PosY = (PageCnt - PageObj.Index) / 4 + 1
'PosY = (PageCnt - PageObj.Index) / 4 + 0.25
'PosY = (PageCnt - PageObj.Index) / 4 + 0.25
PosY = (PageCnt - PageObj.Index) / 4 + 0.25

' draw a rectangle for each page to hold the text
'Set TOCEntry = ActiveDocument.Pages(1).DrawRectangle(1, PosY, 4, PosY + 0.25)
Set TOCEntry = ActiveDocument.Pages(1).DrawRectangle(4.4, PosY, 1, PosY +
0.25)

' write the page name in the rectangle
TOCEntry.Text = PageObj.Name

' 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
 
J

John Marshall, MVP

The examples are made as simple as possible so the basic task is
understandable.

Rather than adding a rectangle for a TOC entry, you can change it so that it
drops a TOC entry shape. The new TOC entry shape can then be customized to
match your criteria. The shape should use custom properties or user
properties to contain the name and page number. The text for the shape would
then contain Insert Fields for the custom/user properties. You would then
need to change the program to drop and position the shape and set it's
custom/user properties.

The other choice is to manipulate the character collections for the shape's
text, not as user friendly as changing the text through the UI.

John... Visio MVP

Need stencils or ideas? http://www.mvps.org/visio/3rdparty.htm
Need VBA examples? http://www.mvps.org/visio/VBA.htm
Common Visio Questions http://www.mvps.org/visio/common_questions.htm
Visio Wishlist http://www.mvps.org/visio/wish_list.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top