Thanks for the tips Vojo.
Especially the part about no vba code.
I currently have vba code that is run when a Page is Added.
The code basically adds a section and property to the page shapesheet. (Prop.Sheet_Title)
I then draw a rectangle on the position I want (lining up with the border from the background). I then set this to the ThePage!Prop.Sheet_Title
All is working good, now trying to get to this data creating a table of contents. For some reason I can't find the field.
I will also study your ideas and apply them if it makes it cleaner.
The basic idea is to have a Title Associated with each page. The Page.Name field is great, but I would like another field where I can be more verbose in describing the page. I can create this by hand after inserting page, but would like it to automatically happen whenever someone inserts a page.
Here is a copy of the code so far.
Sub Add_Title()
' Add Custom Property to Sheet for Sheet Titles
Dim vsoShape As Visio.Shape
Set vsoShape = Visio.ActivePage.PageSheet
vsoShape.AddSection visSectionProp
vsoShape.AddNamedRow visSectionProp, "Sheet_Title", visTagDefault
vsoShape.Cells("Prop.Sheet_Title").Formula = """Dwg Title"""
' Draw Text Box to link to Custom Sheet Title
Application.ActiveWindow.Page.DrawRectangle 13#, 1.068, 16.5, 1.5648
Set vsoShape = Visio.ActiveWindow.Selection(1)
vsoShape.Cells("FillPattern") = 0
vsoShape.Cells("Char.Font") = 21
vsoShape.Cells("Char.Size").Formula = "8 pt"
vsoShape.AddSection visSectionProp
vsoShape.AddNamedRow visSectionProp, Prop_Rows_Name, visTagDefault
Set vsoCharacters = vsoShape.Characters
'vsoCharacters.Text = "sheet title"
vsoCharacters.Begin = 0
vsoCharacters.End = 6
vsoCharacters.AddCustomFieldU "ThePage!Prop.Sheet_Title", visFmtStrNormal
End Sub
This sub is called from
Private Sub Document_PageAdded(ByVal Page As IVPage)
Sheet_Title.Add_Title
Now I am trying to access this field when created a Table of Contents
I borrowed this code from some others on this site
It loops thru each page stopping once it reaches the background pages.
' loop through all the pages
For Each PageToIndex In Application.ActiveDocument.Pages
'exit when it hits the first background page (don't want those in the ToC)
If PageToIndex.Background Then Exit For
If Not PageToIndex.Name = m_deletedPageName Then
'append the page number, a tab, the page name, and a return to the ToC text shape
TOCEntry.Text = TOCEntry.Text + CStr(PageToIndex.Index) + vbTab + PageToIndex.Name + vbNewLine
This works great but now I am trying to add the field created for each page but I cant seem to find the correct syntax or the cell/field itself. Maybe PageToIndex.ShapeSheet is not where it is located?
PageToIndex.PageSheet.Cells("Prop.SheetTitle")
I've tried several combinations but it always dies
Any ideas on how to reference this field
The Text link is ThePage!Prop.Sheet_Title and works fine.
Thanks Again