Dynamic Contents Page with Page Numbers

Eriberi

New Member
Joined
Jan 17, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I am new to VBA and am really struggling to work this one out.
I am creating a document in excel which I want when printed to look like a normal word document or PDF. So far the formatting for this is going well but I have found a hiccup when trying to create a Table of Contents sheet.
At the moment I have 11 sheets in my workbook.
Sheet 1 - Information page (Where my user will put information in that will be added to different sections of the document)
Sheet 2 - Formula Information Page (Basically my dumping point for all the information in my formulas)
Sheets 3-11 - Are my final document sheets.

For the most part all of my "final document sheets" consist of one page per worksheet. However there is one worksheet (worksheet #7) which will be varying pages long depending on the information that gets added. I have got my footer page numbers to work so that no matter how many extra pages get added to worksheet #7 it adjusts the page numbers for the following worksheets.
Now I want to include these page numbers into a table of contents page. I need the table of contents page numbers to automatically update depending on the footer page numbers in each worksheet.
I have tried writing a very simple VBA code to get the information from the footer of each page into the cells for the contents page. However it does not return the actual number value it only returns the page formula (being &P).

Does anyone know how I can get this to work?
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Please reference it

VBA Code:
Option Explicit
Sub Hyper_Link()
Dim ws As Worksheet, K&, Wss As Worksheet
Application.ScreenUpdating = False
Set Wss = Sheets("Mucluc")
    If Wss.Range("B" & Rows.Count).End(3).Row > 4 Then
        Wss.Range("A5:C" & Wss.Range("B" & Rows.Count).End(3).Row).Clear
    End If
    K = 4
        For Each ws In Worksheets
            If ws.Name <> Wss.Name Then
                K = K + 1
                Wss.Range("A" & K) = K - 4
                Wss.Range("B" & K).Value = ws.Name
                Wss.Range("B" & K).Hyperlinks.Add Wss.Range("B" & K), "", "'" & ws.Name & "'!A1"
                Wss.Range("C" & K).Value = ws.Range("C8").Value
            End If
        Next
    Wss.Range("A4:C4").Resize(K - 3).Borders.LineStyle = 1
Application.ScreenUpdating = True
MsgBox "Done"
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top