macro to update page footer number

A

Adi_tca

Hi,

I'm trying to figure out how to withe a macro that automaticall
inserts in the page footer/header the page number when a worksheet ha
more than one page.

I know how to do this manualy. As an example, if in Print Preview show
2 pages, and I want that the page number should start in that workshee
at no. 2, then:: View/Header and Footer/Custom Header/Cente
Section/[&Page]+1.

The question is again: how can this thing be done using a macro?
I tryied something like
ActiveSheet.PageSetup.CenterFooter = "&P"+1 but I get an error message
"Type mismath"

Thanks for any help
 
D

Dave Peterson

ActiveSheet.PageSetup.CenterFooter = "&P+1 "

Notice the extra space following the 1.

Ron de Bruin just posted this for someone else:

http://support.microsoft.com/default.aspx?scid=kb;en-us;48198
XL: Setting Starting Page Number in Header/Footer


And you could get the total pages in the print preview and use it like:

Option Explicit
Sub testme01()

Dim TotalPages As Long

TotalPages = Application.ExecuteExcel4Macro("GET.DOCUMENT(50)")
ActiveSheet.PageSetup.CenterFooter = "&P+" & TotalPages & " "

ActiveSheet.PrintOut preview:=True

End Sub


(and notice that same old extra space, too!)

Adi_tca < said:
Hi,

I'm trying to figure out how to withe a macro that automatically
inserts in the page footer/header the page number when a worksheet has
more than one page.

I know how to do this manualy. As an example, if in Print Preview shows
2 pages, and I want that the page number should start in that worksheet
at no. 2, then:: View/Header and Footer/Custom Header/Center
Section/[&Page]+1.

The question is again: how can this thing be done using a macro?
I tryied something like
ActiveSheet.PageSetup.CenterFooter = "&P"+1 but I get an error message:
"Type mismath"

Thanks for any help.
 
A

Adi_tca

Hi Dave,

Thanks a lot. Before your reply I tryied something similar as yo
suggested, but didn't knew about the extra space...

BR/Adria
 
Top