Use VBA to Open Excel Print Preview and Fit Worksheet Columns
Question details
Use VBA to fit a worksheet's columns to one printed page and open Excel's print preview and print interface.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- The user wants a macro that configures worksheet scaling before previewing or printing.
- Observed behavior
- The desired result is a worksheet that prints one page wide and opens in a print preview or print interface.
Open the workbook in Excel and select the worksheet you want to print. Make sure macros are permitted by your organization's security settings, and save the workbook as an Excel Macro-Enabled Workbook (.xlsm) if you want to retain the code.
Fit the Active Worksheet and Open Excel's Print Interface
Use this macro to set the active worksheet to one page wide and open Excel's Print Preview and Print interface.
In Excel, press Alt+F11, then choose Insert > Module in the VBA editor.
Paste this code into the module: Option Explicit Public Sub PreviewAndPrint() With ActiveSheet.PageSetup .Zoom = False .FitToPagesWide = 1 .FitToPagesTall = False End With Application.CommandBars.ExecuteMso "PrintPreviewAndPrint" End Sub
Return to Excel, select the worksheet, press Alt+F8, select PreviewAndPrint, and click Run. Review the preview and use the Print button when ready.

Preview or Print the Active Worksheet Directly
Use the worksheet's PrintPreview method for a preview, or PrintOut when you want to print without opening a preview first.
Preview and Print Spreadsheets with WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with and printing spreadsheets. Its Microsoft Office format compatibility makes it easier to move existing files; Excel-specific VBA commands may not work the same way in WPS.

Frequently Asked Questions
Why does the macro set Zoom to False?
Excel uses the FitToPagesWide and FitToPagesTall scaling settings when PageSetup.Zoom is False. Set Zoom to False before applying the fit-to-page values.
How do I fit all columns on one page without limiting the number of pages tall?
Set PageSetup.FitToPagesWide to 1 and PageSetup.FitToPagesTall to False, with PageSetup.Zoom set to False.
How can I print without opening the preview?
In the worksheet macro, replace .PrintPreview with .PrintOut. Running the macro will send the active worksheet to the printer.
Which worksheet does the macro affect?
The examples use ActiveSheet, so select the worksheet you want in Excel before running the macro from Alt+F8.




