VBA print formatting help

vbaNumpty

Board Regular
Joined
Apr 20, 2021
Messages
171
Office Version
  1. 365
Platform
  1. Windows
I have the following code to print a sheet:
VBA Code:
Sub Print_DB()

    Dim db As Worksheet
    
    Set db = Sheet1

    Application.PrintCommunication = False

    With db.PageSetup
        
        .FitToPagesWide = 1
        .PaperSize = xlPaperLetter
        .Orientation = xlLandscape
        
    End With
    
    Application.PrintCommunication = True
    
    Range("DBPrint").PrintPreview

End Sub

Right now when I print it forces the entire sheet onto one page, but I only want the width to be confined to the one page and not the whole sheet.

Could someone tell me how I can add the following functions to this macro:
1. Make the width fit on one page, but not the length downwards (I would want it to print the next page with the top two rows as headers)
2. Make margins smaller on all 4 sides
2. Choose the paper size to legal

Any help is greatly appreciated! Thanks
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

rlv01

Well-known Member
Joined
May 16, 2017
Messages
2,025
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Perhaps something like this.

VBA Code:
     'Set margins
        .LeftMargin = Application.InchesToPoints(0.7)
        .RightMargin = Application.InchesToPoints(0.7)
        .TopMargin = Application.InchesToPoints(0.75)
        .BottomMargin = Application.InchesToPoints(0.75)
        .HeaderMargin = Application.InchesToPoints(0.3)
        .FooterMargin = Application.InchesToPoints(0.3)
        
        'Page setup
        .PaperSize = xlPaperLegal
        .Orientation = xlLandscape
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = 0
 
Solution

Forum statistics

Threads
1,186,112
Messages
5,955,913
Members
438,225
Latest member
rsur

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