Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-15-2011, 10:12 AM
judicial85 judicial85 is offline Proper Excel Table of Contents (ToC) Windows 7 Proper Excel Table of Contents (ToC) Office 2010 (Version 14.0)
Advanced Beginner
Proper Excel Table of Contents (ToC)
 
Join Date: Nov 2010
Posts: 64
judicial85 is on a distinguished road
Default Proper Excel Table of Contents (ToC)

The code shown below was taken from the Excel Blog as my Excel tabs are becoming difficult to manage. Would anybody know how to modify it so that the iterations include tabs that are exclusively charts? Right now it only counts/links to spreadsheet pages.

Alternatively, if there is a really nice ToC code out there or tab organizing Add-In or code, could you share the link?

Thanks! Bryan



Code:
Option Explicit

Sub Create_TOC() 
Dim wbBook As Workbook 
Dim wsActive As Worksheet 
Dim wsSheet As Worksheet

Dim lnRow As Long 
Dim lnPages As Long 
Dim lnCount As Long

Set wbBook = ActiveWorkbook

With Application 
    .DisplayAlerts = False 
    .ScreenUpdating = False 
End With

'If the TOC sheet already exist delete it and add a new 
'worksheet.

On Error Resume Next 
With wbBook 
    .Worksheets("TOC").Delete 
    .Worksheets.Add Before:=.Worksheets(1) 
End With 
On Error GoTo 0

Set wsActive = wbBook.ActiveSheet 
With wsActive 
    .Name = "TOC" 
    With .Range("A1:B1") 
        .Value = VBA.Array("Table of Contents", "Sheet # - # of Pages") 
        .Font.Bold = True 
    End With 
End With

lnRow = 2 
lnCount = 1

'Iterate through the worksheets in the workbook and create 
'sheetnames, add hyperlink and count & write the running number 
'of pages to be printed for each sheet on the TOC sheet. 
For Each wsSheet In wbBook.Worksheets 
    If wsSheet.Name <> wsActive.Name Then 
        wsSheet.Activate 
        With wsActive 
            .Hyperlinks.Add .Cells(lnRow, 1), "", _ 
            SubAddress:="'" & wsSheet.Name & "'!A1", _ 
            TextToDisplay:=wsSheet.Name 
            lnPages = wsSheet.PageSetup.Pages().Count 
            .Cells(lnRow, 2).Value = "'" & lnCount & "-" & lnPages 
        End With 
        lnRow = lnRow + 1 
        lnCount = lnCount + 1 
    End If 
Next wsSheet

wsActive.Activate 
wsActive.Columns("A:B").EntireColumn.AutoFit

With Application 
    .DisplayAlerts = True 
    .ScreenUpdating = True 
End With

End Sub
Reply With Quote
  #2  
Old 10-23-2011, 01:35 PM
judicial85 judicial85 is offline Proper Excel Table of Contents (ToC) Windows 7 Proper Excel Table of Contents (ToC) Office 2010 (Version 14.0)
Advanced Beginner
Proper Excel Table of Contents (ToC)
 
Join Date: Nov 2010
Posts: 64
judicial85 is on a distinguished road
Default

Maybe to simplify things, is it even possible to make a hyperlink table of contents on a chart sheet?

When I was going through and polishing some of my other macros, I learned about "worksheets(i)" versus "sheets(i)" which means I can get Excel to select any sheet.
Reply With Quote
Reply

Tags
2010, macro, toc



Similar Threads
Thread Thread Starter Forum Replies Last Post
Table of contents: Hyperlinking tays01s Word 0 08-03-2011 01:41 PM
Proper Excel Table of Contents (ToC) Table of contents: Hyperlinking tays01s Word 11 07-21-2011 12:34 PM
Proper Excel Table of Contents (ToC) Table of Contents - with a twist NuggetSoftware Word 3 06-03-2011 02:51 PM
Table of contents markos97 Word 0 10-26-2010 08:52 AM
Custom Table of Contents NJPhillips Word 1 06-11-2010 12:39 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:34 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft