Your code certainly effects the page layout, but without know the value of
LastRow, hard to say what should happen.
Add a "Debug.Print LastRow" to see if it the expected value.
NickHK
> Guys,
>
[quoted text clipped - 58 lines]
>
> Tristan
relative_virtue@hotmail.com - 18 Jan 2007 10:22 GMT
Nick,
LastRow returns 110 in the case of ActiveSheet. This is as it should
be. Still no change to the PageSetup properties, however.
Tristan
> Your code certainly effects the page layout, but without know the value of
> LastRow, hard to say what should happen.
> Add a "Debug.Print LastRow" to see if it the expected value.
>
> NickHK
relative_virtue@hotmail.com - 18 Jan 2007 10:27 GMT
In fact, by way of proof that it has no effect, here is a Debug.Print
of ActiveSheet.PageSetup.PrintArea before and after this line
.PrintArea = "A1:I" & LastRow + 4
is executed:
BEFORE
?ActiveSheet.PageSetup.PrintArea
$A$1:$AF$114
AFTER
?ActiveSheet.PageSetup.PrintArea
$A$1:$AF$114
Tristan
What happens when you set a breakpoint in Workbook_BeforePrint and step
through the code?
> Guys,
>
[quoted text clipped - 58 lines]
>
> Tristan
relative_virtue@hotmail.com - 18 Jan 2007 10:57 GMT
> What happens when you set a breakpoint in Workbook_BeforePrint and step
> through the code?
It steps through fine. VBA doesn't throw up any errors, it all seems
to execute without a hitch - it's just that the properties don't seem
to be in the least bit affected by the code.
One thing to mention is that this did work okay once upon a time - the
current PageSetup properties were initially set by this code. But now
they won't change, so if I alter, say, Orientation to xlPortrait, it
still comes out as landscape. The main aim of this code is to change
the PrintArea depending on whether it is just being Printed or Print
Previewed normally or whether it has been called through the
TogglePrint routine, but I can't change it at all.
I've also tried using ThisWorkbook.Names to delete and then add a
"Print_Area" name with the appropriate string value. But though it
deleted the Name and didn't throw up an error at the .Names.Add line,
no new Name appeared.
Very peculiar.
Tristan