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
 

Tazguy37

MrExcel MVP
Joined
May 28, 2004
Messages
4,237
Is that all of the page setup code? I'm using XL2k, and the page comes out in landscape when I preview it.
 

royboy531

Board Regular
Joined
Nov 11, 2005
Messages
52
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
 

Tazguy37

MrExcel MVP
Joined
May 28, 2004
Messages
4,237
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!
 

royboy531

Board Regular
Joined
Nov 11, 2005
Messages
52
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
 

Forum statistics

Threads
1,078,373
Messages
5,339,814
Members
399,333
Latest member
Grace Ford

Some videos you may like

This Week's Hot Topics

Top