VBA code to change the print setup

notanexpert

Board Regular
Joined
May 21, 2009
Messages
142
I tried to do a macro by going into the sheet and changing view to page preview and adjusting the margins. but it didn't do right.

All the sheets that i will use this macro on will be the same setup so i need page 1 (the only page) to be
a1:as74
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
If you turn on the Macro Recorder and record yourself performing these steps manaully, it should give you the VBA code you desire.
 
Upvote 0
i tried that a couple of times and wasn't able to get it to work when i put it into the code. but i will give it another shot
 
Upvote 0
If you continue to have problems, post the code you are generating, and explain exactly what settings you are trying to change (and to what values).
 
Upvote 0
Try this: right click the Excel logo just to the left of File on the menu bar, select View Code and paste in

Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim ws As Worksheet
For Each ws In ActiveWindow.SelectedSheets
    ws.PageSetup.PrintArea = "A1:AS74"
Next ws
End Sub

Then press ALT + Q to close the code window. The print range should now be set automatically when you print (or print preview).
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,557
Members
449,088
Latest member
davidcom

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