Follow up on making a ToC for Visio. Anyone handy / want a challenge on tweaking existing scripts or making a new VBA script macro?

Thanks to someone here and finding another script on the web, I realize I'd like parts from both of these scripts.  

The script that Scott wrote / posted in:

https://www.experts-exchange.com/questions/29090658/Is-there-a-way-to-make-a-dynamic-table-of-contents-page-in-Visio.html#a42510143

sorts alphabetically, which I realized, I really need.  But puts each entry in separate text boxes.

The script I found in:

http://www.stephen.turbek.com/articles/2007/04/automatically-create-table-of-contents.html

Sorts by page number and puts all the text in a single text box / easier for me to format text, etc.
Sub table_of_contents_creator()
'this macro creates a table of contents in a visio document by
'going through the pages in the document and adds the page number and page title

'by stephen turbek s@stephenturbek.com
'written for use in microsoft visio 2003 SP1

'adapted from http://www.greenonions.com/tocscript
'I added allowing user to select a text box and replace the contents, rather than build lots of little boxes
'this way you can style the text easily, and simply replace the contents when you update the doc
'note: this is my first VB script

' define a shape to use for the Table of Contents (TOC)
Dim TOCEntry As Visio.Shape

'get selection
Dim selectedShapes As Selection
Set selectedShapes = ActiveWindow.Selection

'is any shape selected to put the ToC in?
If selectedShapes.Count > 0 Then
    'take the selected shape to put the table of contents in
    Set TOCEntry = ActiveWindow.Selection.Item(1)
Else
    'nothing is selected, create a shape
    Set TOCEntry = ActiveDocument.Pages(1).DrawRectangle(1, 1, 7.5, 10)
    
    TOCEntry.Cells("VerticalAlign").Formula = "0"  'make text box top vertically aligned
    TOCEntry.Cells("Para.HorzAlign").Formula = visHorzLeft 'make text box left aligned
    
End If

'clear out the shape's text
TOCEntry.Text = ""

'a variable to hold the page array
Dim PageToIndex As Visio.Page

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

Next
End Sub

Open in new window


I'd love to have 2 macros (at most... if 1 macro could do both, great!).  

1) the 2nd one by Stephen is great as is.
2) another macro that does the same as Stephen's but instead of sort by page number, sorts by page name

I looked at the 2 of them, but my skill set is maxed out in doing things like changing the order of text in Stephens - swapping the page number and name on the same line. But still sorted by page number.  And even with that, with page name first, because page names are different lengths, the numbers aren't all in a single column. -
A) anyone able / interested in doing this?

Not sure if taking Scott's script for sorting alphabetically and getting it to run on Stephen's script using a single text box  is the best way...

And yeah, I could see the ToC page having 2 separate text boxes / running each macro after choosing the appropriate text box (so 2 lists of pages, 1 sorted by page number, 1 sorted by page name).
BeGentleWithMe-INeedHelpAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott HelmersVisio Consultant, Trainer, Author, and DeveloperCommented:
I understand your interest in having all TOC entries in one text box but there is a very specific reason why I used a separate shape for each entry: hyperlinks. The target page in every case is one click away (one Ctrl+click to be more accurate). I find the presence of hyperlinks to outweigh most other considerations, however, I certainly understand that others may have different views.

In any case, I modified by code to allow you to sort by either page name or page number, so there are now two macros -- one for each. I've also uploaded a document containing the code with instructions on the first page.
Create-Visio-Table-of-Contents-v3--b.vsd
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BeGentleWithMe-INeedHelpAuthor Commented:
WOW! I didn't get to try this out, but THANK YOU!!  Amazing what you can do when you know what you are doing : )

Yes, the hyperlinks are nice!

But I was thinking when I print this out (and I've been using your other ToC macro a few times now on 20 - 30 page networks... and several times I am looking for a page in the ToC and having to go down the numbered list.  And I print them out to mark up changes. trying to do that on a tablet / laptop, at least for me, means I wouldn't bother. so for that, hyperlinks aren't as valuable.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Visio

From novice to tech pro — start learning today.