I have some VBA code set up to take a sheet name, range (prntRange
), and orientation (prntOrient
) and print the result, but it seems like VBA is ignoring the commands for the page setup. Here's a quick snippet:
For x = 1 To numPages
Worksheets("Printing").Activate
prntSheet = Cells(6 + (x - 1), 1)
prntRange = Cells(6 + (x - 1), 2)
prntOrient = Cells(6 + (x - 1), 3)
Application.StatusBar = "Printing " & prntSheet & "..."
Worksheets(prntSheet).Activate
With ActiveSheet.PageSetup
.PrintArea = False
If prntOrient = "Portrait" Then
.Orientation = xlPortrait
Else
.Orientation = xlLandscape
End If
.PrintArea = prntRange
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
...
And here's an example of the table:
Sheet Name Range Orientation
Example A1:J56 Portrait
Example A1:J80 Landscape
prntRange
pulls from Range, prntOrient
pulls from Orientation
Basically what I'm looking for is a portrait version of the range A1:J56
of Example, and then a landscape version of the range A1:J80
of Example. The landscape version prints as two pages despite being told to be fit to one page. This happens whether or not that first entry is also there, and whether or not I manually reset the printing setting in Excel.
I've tried pretty much every permutation of the four commands above and order doesn't seem to make a difference. Setting .PrintArea = False
was me thinking that refreshing the print area might help, but I don't believe it does. If I go through these steps manually then I have no problem getting it into the desired format, but the entire point of this macro is so that I don't have to do that.
Does anyone have any idea what I'm missing?
Thanks in advance!
EDIT: More accurate title.
EDIT 2: More detail per people's requests, sorry!
EDIT 3: Expanding code to show variable assignments