This article describes different print methods in order to print pages via a button or by simply using the macro menu in Excel. Assigning VBA codes/ macros to a button is described in this article.
Print active page
This macro prints the sheet that is currently active, i.e. you are seeing/ working on. This code will not ignore print areas.
If your current active sheet consists out of more than 1 page and you want to print out specified pages you could use the following code. Excel will print pages 4 to 6.
ActiveSheet.Printout From:=4, To:=6
To print multiple copies:
ActiveSheet.Printout From:=4, To:=6, Copies:=2
Print defined page(s)
Perhaps, if you have a dashboard with multiple buttons, you wish to print a specified worksheet. Therefore, ‘ActiveSheet’ has to be changed into the following:
Sheets(“Name of the sheet to print”).PrintOut
Or in case of multiple worksheets:
Worksheets(Array(“AAA”, “BBB”, “DDD”)).PrintOut
Or in case of the whole workbook:
Print a page, fit on one page.
This code scales the page to fit on one page and prints.
On Error Resume Next
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
‘Change .FitToPagesTall = 1 to = False if you want to change the fit to width only.
‘Change .FitToPagesTall = 1 to = False if you want to change the fit to Wide only.
If you want to edit the print preview menu (select printers and other options) you have to change the ‘PrintOut’ command: