Excel VBA - How to Insert Sequential Page Number

时间:2016-08-31 17:56:52

标签: excel vba excel-vba

I would like to insert sequential page number across the entire workbook (there are two worksheets in the workbook.

Here is my code to insert page numbers:

ActiveWorkbook.Worksheets("Appendix A").PageSetup.CenterFooter = "&P of &N"
ActiveWorkbook.Worksheets("Summary").PageSetup.CenterFooter = "&P of &N"

1 个答案:

答案 0 :(得分:1)

If you mean you want to write the index of the current sheet out of the entire number of sheets in your ActiveWorkbook, then use the following code:

ActiveWorkbook.Worksheets("Appendix A").PageSetup.CenterFooter = "Page " & ActiveWorkbook.Worksheets("Appendix A").Index & " of " & ActiveWorkbook.Sheets.Count
ActiveWorkbook.Worksheets("Summary").PageSetup.CenterFooter = "Page " & ActiveWorkbook.Worksheets("Summary").Index & " of " & ActiveWorkbook.Sheets.Count