vba courses london - create contents page
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

Forum home » Delegate support and help forum » Microsoft VBA Training and help » vba courses london - Create a contents page

vba courses london - Create a contents page

resolvedResolved · Low Priority · Version Standard

replyReply Thu 18 Jan 2007, 16:07Delegate David said...

David has attended:
Excel VBA Intro Intermediate course

Create a contents page

Hi there,

I'd like to have a macro which sits in my personal macro workbook that allows me to create a contents page for any excel workbook I access.

The contents page should include:
- a list of all the individual worksheets
- each worksheet name should also be a hyperlink to cell a1 of the corresponding sheet

It would also be handy to have the ability to
-name the contents page if a worksheet titled 'contents' already exists; and
- subsequently update the contents of the 'contents' worksheet I create.

Thanks!

For upcoming training course dates see: Pricing & availability

replyReply Fri 26 Jan 2007, 12:34 Edited on Fri 26 Jan 2007, 12:37Trainer Carlos said...

Create a contents page Using A Loop

A simple way of doing this is on startup run a procedure that does the following:

1. Creates a new Spreadsheet Call it "Contents Page". You need to check if "Contents Page" already exists and delete it

2. Does a loop that checks each sheet in the book

3. Inside this loop create another loop that using a row counter pastes the name of the sheet in a cell on the "Contents Page" and Hyperlinks it to the named sheet as seen in the routine below:

Sub ContentSheet

Dim vSheet As Worksheet
Dim RowNum As Integer

RowNum = 2

Sheets.Add Before:=Sheets(1)
ActiveSheet.Name = "Contents Page"

For Each vSheet In ActiveWorkbook.Worksheets

'You could test for "Contents Page" and ignore it here

Sheets("Contents Page").Select
Cells(RowNum, 1).Select
ActiveCell.Value = vSheet.Name

ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
vSheet.Name & "!A1", TextToDisplay:=vSheet.Name

RowNum = RowNum + 1

Next vSheet

End Sub

 

Vba tip:

Use GoTo to Select A Cell With VBA

To select a certain cell on a Worksheet you can use:

Application.Goto Reference:=Range("V300")

or more simply

Range("V300").Select

If, on the other hand, you want the selected cell to be the top/left cell on the screen you use:

Application.Goto Reference:=Range("V300"), Scroll=True

View all VBA hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard