not converting to landscape in my macro

royboy531

Board Regular
Joined
Nov 11, 2005
Messages
52
I put together a macro to print a report that needs to be changed from portrait to landscape. In the code it says ".Orientation = xlLandscape" but the page still comes out in portrait. here is that part of the code

Code:
With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = "&D  &T"
        .RightHeader = ""
        .LeftFooter = ""
        .CenterFooter = ""
        .RightFooter = ""
        .LeftMargin = Application.InchesToPoints(0.5)
        .RightMargin = Application.InchesToPoints(0.5)
        .TopMargin = Application.InchesToPoints(1)
        .BottomMargin = Application.InchesToPoints(1)
        .HeaderMargin = Application.InchesToPoints(0.5)
        .FooterMargin = Application.InchesToPoints(0.5)
        .PrintHeadings = False
        .PrintGridlines = False
        .PrintComments = xlPrintNoComments
        .PrintQuality = -3
        .CenterHorizontally = True
        .CenterVertically = False
        .Orientation = xlLandscape
        .Draft = False
        .PaperSize = xlPaperLetter
        .FirstPageNumber = xlAutomatic
        .Order = xlDownThenOver
        .BlackAndWhite = True
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = 1
    End With

can anybody see any problems?? I'm lost
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Is that all of the page setup code? I'm using XL2k, and the page comes out in landscape when I preview it.
 
Upvote 0
that is not all the code. Here is the whole thing.

Code:
Private Sub btnFilter_Click()
   
    Dim startDate As String
    Dim shift As String
    
    'reads date from the userform
    startDate = tbstartdate.Value 'tbStartDate is the name of the textbox for Starting Date
    shift = tbshift 'tbshift is the name of the textbox for shift
    
    'FILTERS
    With Worksheets("sheet1")
        .AutoFilterMode = False
        .Range("a1:p1").AutoFilter
        .Range("a1:p1").AutoFilter Field:=2, Criteria1:=shift
        .Range("a1:p1").AutoFilter Field:=1, Criteria1:=(">=" & startDate), _
            Operator:=xlAnd, Criteria2:=("<=" & startDate)
       
        Me.Hide
        
        Range("A1:P" & Cells(Rows.Count, "A").End(xlUp).Row).Select
End With
 Selection.Copy
    Workbooks.Add
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Selection.Sort Key1:=Range("E2"), Order1:=xlAscending, Key2:=Range("C2") _
        , Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
        False, Orientation:=xlTopToBottom
    Selection.Subtotal GroupBy:=3, Function:=xlAverage, TotalList:=Array(6, 7, _
        8, 9), Replace:=True, PageBreaks:=False, SummaryBelowData:=True
    ActiveWindow.SmallScroll Down:=-3
    Range("A1:P" & Cells(Rows.Count, "A").End(xlUp).Row).Select
    Selection.AutoFormat Format:=xlRangeAutoFormatSimple, Number:=True, Font _
        :=True, Alignment:=True, Border:=True, Pattern:=True, Width:=True
    ActiveWindow.SmallScroll ToRight:=5
    Range("A1:P1").Select
    Range("P1").Activate
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Columns("K:K").ColumnWidth = 8.57
    ActiveWindow.SmallScroll ToRight:=-7
    Columns("G:G").ColumnWidth = 8.43
    Columns("F:F").ColumnWidth = 9.43
    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = "&D  &T"
        .RightHeader = ""
        .LeftFooter = ""
        .CenterFooter = ""
        .RightFooter = ""
        .LeftMargin = Application.InchesToPoints(0.5)
        .RightMargin = Application.InchesToPoints(0.5)
        .TopMargin = Application.InchesToPoints(1)
        .BottomMargin = Application.InchesToPoints(1)
        .HeaderMargin = Application.InchesToPoints(0.5)
        .FooterMargin = Application.InchesToPoints(0.5)
        .PrintHeadings = False
        .PrintGridlines = False
        .PrintComments = xlPrintNoComments
        .PrintQuality = -3
        .CenterHorizontally = True
        .CenterVertically = False
        .Orientation = xlLandscape
        .Draft = False
        .PaperSize = xlPaperLetter
        .FirstPageNumber = xlAutomatic
        .Order = xlDownThenOver
        .BlackAndWhite = True
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = 1
    End With
    ActiveWindow.SelectedSheets.PrintPreview
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
    ActiveWindow.Close
    Range("A279").Select
    Selection.AutoFilter
    Selection.AutoFilter
End Sub

I have tried this on 2 different excel versions I think 97and 03
 
Upvote 0
You might try setting the print area before you actually print. I don't see that anywhere in your code. Something like:

Code:
.PrintArea = ActiveSheet.UsedRange.Address

Hope that helps!
 
Upvote 0
TazGuy, I have another problem with this code and maybe you can help me. When the macro gets to "With ActiveSheet.PageSetup" and goes through the page set up it is in print preview area and the macro freezes. when I hit close the macro continues. the other problem I have is a pop up box comes up to close the new book and asks if I want to save changes. i want to have in the macro to automatically close and not save changes.

about the first question I was inquiring about, when I tried on a different computer and different printer I didn't have a landscape problem. maybe it's a printer thing???

thanks for your help
royboy531
 
Upvote 0

Forum statistics

Threads
1,213,482
Messages
6,113,913
Members
448,532
Latest member
9Kimo3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top