VBA code to set print preferences

571202

New Member
Joined
May 26, 2019
Messages
47
Hi, I need a VBA code to set the print preferences for all the worksheets in my workbook (in Personal) to narrow margins, landscape and A3.......hopefully with one sub to do all the sheets at once. Cheers.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Hi,

As long as your printing preferences are valid within your workbook ... there is no need to store your macro in Personal ...
 
Upvote 0
Hi, a report is sent to several people and I'm installing the macro on their computers so they can just run the macro after they open the reports.

Yes.....I know....it scary that I'm installing macros on other peoples computers but I'm the best of a hopeless mob :)
 
Upvote 0
The problem has been solved......I was activating an individual sheet, removed that and it now does all sheets.
VBA Code:
Private Sub PrintSetup()
        With ActiveSheet.PageSetup
        .LeftMargin = Application.InchesToPoints(0.25)
        .RightMargin = Application.InchesToPoints(0.25)
        .TopMargin = Application.InchesToPoints(0.75)
        .BottomMargin = Application.InchesToPoints(0.75)
        .HeaderMargin = Application.InchesToPoints(0.3)
        .FooterMargin = Application.InchesToPoints(0.3)
        .Orientation = xlLandscape
        .PaperSize = xlPaperA3
        .Zoom = 100
        End With
    Application.PrintCommunication = True
End Sub
 
Upvote 0
For all worksheets in one shot
VBA Code:
Private Sub PrintSetup()
    Dim ws As Worksheet

    For Each ws In ThisWorkbook.Worksheets
        With ws.PageSetup
            .LeftMargin = Application.InchesToPoints(0.25)
            .RightMargin = Application.InchesToPoints(0.25)
            .TopMargin = Application.InchesToPoints(0.75)
            .BottomMargin = Application.InchesToPoints(0.75)
            .HeaderMargin = Application.InchesToPoints(0.3)
            .FooterMargin = Application.InchesToPoints(0.3)
            .Orientation = xlLandscape
            .PaperSize = xlPaperA3
            .Zoom = 100
        End With
        Application.PrintCommunication = True
    Next ws
End Sub
 
Upvote 0
Hi, @YasserKhalil , thanks for your reply. Unfortunately it didn't work for my macro. I inserted it as the last sub....is that correct. I am using Personal, not a Workbook if that makes a difference. What do you think the problem might be? Cheers.
 
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,749
Members
449,050
Latest member
excelknuckles

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