views:

463

answers:

1

I am creating a C# windows application to create an Excel 2003 sheet. There is a requirement to add to the footer: Page 1 of 4.

I currently have it so it puts "Page: &[Page] of &[Pages]" into the footer of the excel sheet.

When I open up the created document and look at the footer I see "Page: Page] of Pages]"

I can click on the text, it highlights it and shows what it should, and works correctly after that.

Is there any way to get it to work correctly from the start?

+1  A: 

In Excel 2007 if you type this as your footer:

Page &[Page] of &[Pages]

Then go into the VBA editor Immediate window and enter this:

print ActiveSheet.PageSetup.CenterFooter

the result is:

Page &P of &N

In other words, the value set in the code is different from the one typed in the user interface.

Given that Microsoft treats backward compatibility like some kind of holy writ, I strongly suspect you're seeing the same thing in Excel 2003 - try modifying your code to set "Page &P of &N" instead.

Bevan