VBA & Macro Problems

Use VBA to Open Excel Print Preview and Fit Worksheet Columns

Nimra MalikNimra Malik Nov 27, 2026 870 views

Question details

Use VBA to fit a worksheet's columns to one printed page and open Excel's print preview and print interface.

Use VBA to Open Excel Print Preview and Fit Worksheet Columns
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA editor

In Excel, press Alt+F11, then choose Insert > Module in the VBA editor.

2
Add the macro

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

3
Run the macro

Return to Excel, select the worksheet, press Alt+F8, select PreviewAndPrint, and click Run. Review the preview and use the Print button when ready.

Fit the Active Worksheet and Open Excel's Print Interface
Page height: FitToPagesTall = False leaves the number of pages tall unrestricted. Set it to a number such as 10 if you need a maximum page height.
Free Microsoft Office alternative

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.

Preview spreadsheets and adjust print settings in WPS SpreadsheetsOpen and work with Microsoft Excel formats such as XLSXUse a familiar interface for a smoother transition from Microsoft OfficeWork with a free, lightweight office suite
microsoft office alternative - wps office

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.