VBA & Macro Problems

Set Print Areas for Multiple Excel Worksheets with VBA

Khadija KhanKhadija Khan Nov 27, 2026 869 views

Question details

Set print areas and consistent page settings for more than 200 worksheets using VBA.

Set Print Areas for Multiple Excel Worksheets with VBA
Product
Microsoft Excel
Device & OS
not provided
Scenario
The user wants each worksheet configured with half-inch margins, landscape orientation, and scaling to one page wide.
Observed behavior
Each worksheet should print its intended content one page wide, with rows allowed to continue onto additional pages.
Before you start

Check that each worksheet's used range contains the cells you want to print; formatting in distant cells can make it larger than expected. Save the workbook as an Excel Macro-Enabled Workbook (.xlsm) and enable macros if prompted.

Solution 1Recommended

Apply print settings to every worksheet with a VBA macro

Use this macro to configure all worksheets at once, then review the results before printing.

The macro uses each sheet's UsedRange as its print area. It sets the left, right, top, and bottom margins to 0.5 inches and allows an unlimited number of pages tall.

1
Open the VBA editor

In Excel, open the workbook and select Developer > Visual Basic. If the Developer tab is hidden, enable it through File > Options > Customize Ribbon.

2
Insert a module

In the VBA editor, select Insert > Module, then paste this code: Sub SetPrintAreas() Dim W As Worksheet For Each W In ThisWorkbook.Worksheets With W.PageSetup .PrintArea = W.UsedRange.Address .LeftMargin = Application.InchesToPoints(0.5) .RightMargin = Application.InchesToPoints(0.5) .TopMargin = Application.InchesToPoints(0.5) .BottomMargin = Application.InchesToPoints(0.5) .Orientation = xlLandscape .Zoom = False .FitToPagesWide = 1 .FitToPagesTall = False End With Next W End Sub

3
Run and review the macro

Place the cursor inside SetPrintAreas and select Run > Run Sub/UserForm, or press F5. In Excel, select a few worksheets and open File > Print to check their previews.

4
Print the worksheets

When the previews look right, select File > Print and choose Print Entire Workbook. Alternatively, add W.PrintOut after the End With line in the loop and run the macro to print each sheet automatically.

Apply print settings to every worksheet with a VBA macro
Limit the number of pages tall: To fit each worksheet within a maximum of five pages tall, change .FitToPagesTall = False to .FitToPagesTall = 5. Excel may shrink the content further to meet that limit.
Free Microsoft Office alternative

Review and Print Excel Workbooks with WPS Office

WPS Office is a free, lightweight alternative with a familiar spreadsheet interface for opening and printing Excel workbooks. Its format compatibility helps with migration, though Excel VBA macros and their behavior may differ in WPS.

Review worksheet page layouts and print settings in WPS SpreadsheetOpen and edit Microsoft Excel formats, including XLSX and XLSM filesWork in a familiar spreadsheet interfaceUse a free, lightweight alternative for everyday office tasks
microsoft office alternative - wps office

Frequently Asked Questions

Why is the print area larger than my data?

UsedRange can include cells with formatting beyond the visible data. If the intended data is contiguous, replace W.UsedRange.Address with W.Range("A1").CurrentRegion.Address, using a cell inside the desired region instead of A1.

Why does the macro set Zoom to False?

In VBA, PageSetup.Zoom must be False for FitToPagesWide and FitToPagesTall scaling to take effect. The macro then sets FitToPagesWide to 1.

Can I make each worksheet fit within five pages tall?

Yes. In the macro, change .FitToPagesTall = False to .FitToPagesTall = 5. Check File > Print afterward because fitting to a page limit can make the content smaller.

Does the macro print the sheets immediately?

No. The supplied macro only changes page settings. After checking File > Print, choose Print Entire Workbook, or add W.PrintOut inside the loop to print each sheet automatically.