How to make the shape appear on page 2

Started by bmalak, August 08, 2022, 04:07:33 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

bmalak

How can this code be changed to make the shape appear on page 2 instead of the first page of the drawing? Also is there a way to reduce the spacing between the rectangles so they are touching? Thanks!



Sub TableOfContents()
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

PageCnt = 0
For Each PageObj In ActiveDocument.Pages
If PageObj.Background = False Then PageCnt = PageCnt + 1
Next

For Each PageObj In ActiveDocument.Pages
If PageObj.Background = False Then
PageNr = PageNr + 1

PosY = (PageCnt - PageObj.Index) / 4 + 2

Set TOCEntry = ActiveDocument.Pages(1).DrawRectangle(1, PosY, 3.5, PosY + 0.125)
TOCEntry.Cells("Para.HorzAlign").Formula = visHorzLeft

TOCEntry.Text = PageNr & "." & " " & PageObj.Name & vbTab

Set CellObj = TOCEntry.CellsSRC(visSectionObject, visRowEvent, visEvtCellDblClick)

CellObj.Formula = "GOTOPAGE(""" + PageObj.Name + """)"
End If
Next
End Sub

Paul Herber

The line:
Set TOCEntry = ActiveDocument.Pages(1).DrawRectangle(1, PosY, 3.5, PosY + 0.125)
contains the index to the page!
Also in your code, PageNr is not initialized.
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/