Excel VBA Problem in Page Footer

MacNew

New Member
Joined
Jun 18, 2014
Messages
4
Sub FormattedPageNums()
Dim iPages As Integer
Dim J As Integer
Dim sFormat As String

sFormat = "00000"
' Get count of pages in active sheet
iPages = ExecuteExcel4Macro("Get.Document(50)")

With ActiveSheet
For J = 1 To iPages
.PageSetup.CenterFooter = Format(J, sFormat)
.PrintOut From:=J, To:=J
Next J
End With
End Sub

I obtained the above code from a site. But when i ran it, all the footer have the last page number.
e.g.If my sheet has 2 pages, footers have 00002 for all 2 pages, if i have 3 pages, footers have 0003 for all 3 pages. Could you please help me with this? (I am using Excel 2007 version)
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
All pages use the same footer, so each time you set the centrefooter you're resetting all the pages to the same footer.
Try using &[Page] , but you can't format it AFAIK
 
Upvote 0

Forum statistics

Threads
1,215,378
Messages
6,124,603
Members
449,174
Latest member
ExcelfromGermany

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