VBA Print Help

hajiali

Active Member
Joined
Sep 8, 2018
Messages
488
Office Version
  1. 2016
Platform
  1. Windows
VBA Code:
If Range("BA1").Value = 1 Or Range("BA1").Value = 2 Then
    Range("AB7").Value = "EE #"
    Range("Y1").Value = 1
    lastR = Range("BC2").Value
    ActiveSheet.PageSetup.PrintArea = "$A$22:$O$82,$AA$5:AX" & lastR
    With ActiveSheet.PageSetup
        .LeftMargin = Application.InchesToPoints(0.25)
        .RightMargin = Application.InchesToPoints(0.25)
        .TopMargin = Application.InchesToPoints(0)
        .BottomMargin = Application.InchesToPoints(0)
        .HeaderMargin = Application.InchesToPoints(0)
        .FooterMargin = Application.InchesToPoints(0)
        .PrintComments = xlPrintSheetEnd
        .PrintQuality = 600
        .Orientation = xlPortrait
        .PaperSize = xlPaperLegal
        .FirstPageNumber = xlAutomatic
        .Order = xlDownThenOver
        .FitToPagesTall = 1
        .PrintErrors = xlPrintErrorsDisplayed
        .ScaleWithDocHeaderFooter = True
        .AlignMarginsHeaderFooter = True
    End With
    z = ActiveSheet.PageSetup.Pages.Count
    ActiveWindow.SelectedSheets.PrintOut From:=2, To:=z, copies:=x, Collate _
        :=True, IgnorePrintAreas:=False

with Range("BA1").Value is 1 or 2 the macro runs through the above code fine except that it prints on Letter size paper although in the code I specified in the code ".PaperSize = xlPaperLegal"

can not seem to figure out why. Any help is greatly appreciated.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Alex Blakenburg

MrExcel MVP
Joined
Feb 23, 2021
Messages
5,100
Office Version
  1. 365
Platform
  1. Windows
Can you confirm that if you print it manually, legal size does what it is supposed to do ?
(to rule out a printer driver issue)
Can you also confirm that you are not needing to select a specific printer tray eg there is one loaded with Letter and one with Legal ?
I don't believe you can control that in VBA.
 
Solution

hajiali

Active Member
Joined
Sep 8, 2018
Messages
488
Office Version
  1. 2016
Platform
  1. Windows
Thanks for the Info Alex that did the trick just double check the printer settings on it. works
 

Forum statistics

Threads
1,176,138
Messages
5,901,571
Members
434,906
Latest member
Prabhu_Churi

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
Top