Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Page &P of &N doesn't give expected result

Status
Not open for further replies.

PWD

Technical User
Jul 12, 2002
823
GB
Good afternoon. Just a follow-up on my previously posted question really. Why should the following code only produce the expected result if I insert a Breakpoint & step (F8) through the code but not if I just let it run as part of the rest of the code?

Code:
    Application.PrintCommunication = False

    With ActiveSheet.PageSetup
        .CenterFooter = "Page &P of &N"
        .RightFooter = "&D"
        .Orientation = xlLandscape
        .PaperSize = xlPaperA4
        .FitToPagesWide = 1
        .FitToPagesTall = 0
        .PrintTitleRows = "$1:$2"
        .PrintTitleColumns = ""
    End With
    Application.PrintCommunication = True

Many thanks,
D€$
 


hi,

Should we just guess at 1) the actual result and 2) the expected result and 3) the structure of the data on the sheet you are printing, 4) the margins, 5) the printer driver, 6) the range of data, uh what else???

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Try this -

.CenterFooter = Chr(38) & Chr(34) & "Calibri" & Chr(34) & Chr(38) & "11" & "Page &P of &N"


You will need to change the font and font size from Calibri 11 to whatever you are using.
 
Have you tried it after commenting out the lines "Application.PrintCommunication = False" and "Application.PrintCommunication = True"?

soi là, soi carré
 
Skip. Harsh! (It's probably my own fault for having 5 minutes at the end of the day & rushing out these questions.)

If I just open a new workbook, 'Book1.xlsm' and put numbers from cells A1 to P37 then run this code:-
Code:
Sub TestDesFooters()
    Application.PrintCommunication = False

    With ActiveSheet.PageSetup
        .CenterFooter = "Page &P of &N"
        .RightFooter = "&D"
        .Orientation = xlLandscape
        .PaperSize = xlPaperA4
        .FitToPagesWide = 1
        .FitToPagesTall = 0
        .PrintTitleRows = "$1:$2"
        .PrintTitleColumns = ""
      End With
    Application.PrintCommunication = True
End Sub

All I get in the Footer is:-

Code:
Center section:
Page &[Page] of

Having done that and then just step (F8) throught the same code on the same sheet without saving it, I only get:-
Code:
Right section:
&[Date]

If I open another new workbook & just F8 through the code, it's all as I want and I get:-

Code:
Center section:
Page &[Page] of &[Pages]
Right section:
&[Date]

If I omit,
Code:
Application.PrintCommunication = False
Code:
The I get an error 1004 message:-
"Unable to set the FitToPagesTall property of the PageSetup class"
Although it doesn't if I change the line to:-

Code:
        .FitToPagesTall = False

I don't know if margins or printer driver make any significant difference. All I know is what I've put above. F8 = OK, F5 isn't.

Many thanks,
D€$
 
With the Application.PrintCommunication still commented out, can you add in
Code:
.Zoom = False
?

soi là, soi carré
 
How many printed pages do you get when you set zoom to 10% (esp. horizontal direction)?
You should stay with [tt].FitToPagesTall = False[/tt], it represents blank number in page setup.

combo
 
Curiously, after adding the .zoom, it appears to work just fine:-

Code:
Sub TestDesFooters()

    With ActiveSheet.PageSetup
        .Zoom = False
        .CenterFooter = "Page &P of &N"
        .RightFooter = "&D"
        .Orientation = xlLandscape
        .PaperSize = xlPaperA4
        .FitToPagesWide = 1
        .FitToPagesTall = False
        .PrintTitleRows = "$1:$2"
        .PrintTitleColumns = ""
      End With

End Sub

It's curiously slow - about 5 seconds (this test sheet is still small "A1" to "P44")!! - but, hey!!

Thanks all round :)

Many thanks,
D€$
 

on your first code, I needed to add the zoom and change the FitToPagesTall to false
Code:
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = False
Having done so, I get the Page n of m either running or stepping.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Yes indeed Skip. Result!!

Many thanks,
D€$
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top