How to Display Print Preview in Excel VBA: Step-by-Step Guide with Practical Use Cases
Contents
- How to Display Print Preview in Excel VBA: Step-by-Step Guide with Practical Use Cases
- ✅ Why Use Print Preview in Excel VBA
- ✅ Understanding Print Preview in Excel VBA
- ✅ Step 1: Display Basic Print Preview with a Macro
- ✅ Step 2: Add a Print Preview Button on the Sheet
- ✅ Step 3: Display Print Preview for a Specific Sheet
- ✅ Step 4: Display Print Preview for Multiple Sheets
- ✅ Step 5: Automatically Apply Page Settings Before Preview
- ✅ Step 6: Preview a Defined Print Area Only
- ✅ Step 7: Add a Confirmation Message Before Preview
- ✅ Step 8: Integrate Preview and Print in One Macro
- ✅ Step 9: Preview Before Exporting to PDF
- ✅ Step 10: Customizing Print Preview Buttons for Teams
- ✅ Step 11: Create a Dynamic Print Preview System for All Sheets
- ✅ Step 12: Automatically Trigger Print Preview When Opening the File
- ✅ Step 13: Add Print Preview to a Ribbon Button or Shortcut
- ✅ Step 14: Handle Large Files Gracefully
- ✅ Step 15: Integrating Print Preview into RPA Workflows
- ✅ Step 16: Troubleshooting Print Preview Issues
- ✅ Step 17: Real-World Business Use Cases
- ✅ Step 18: Combining Print Preview with Other VBA Features
- ✅ Step 19: Enhancing User Interface for Print Preview
- ✅ Step 20: Full Example – Professional Preview Macro
- ✅ Summary: Master Print Preview Automation in Excel VBA
When preparing Excel reports, the Print Preview feature is one of the most important yet underrated tools. It allows you to verify margins, orientation, scaling, and overall layout before committing to printing or PDF export.
However, in many organizations, users forget to preview their sheets, resulting in wasted paper, incomplete pages, or broken formatting. Automating Print Preview using Excel VBA solves this problem elegantly — ensuring that users always confirm layout before printing.
This comprehensive guide walks you through how to display Print Preview using VBA, customize it for different workflows, and integrate it into real-world business automation scenarios.
✅ Why Use Print Preview in Excel VBA
While the Print Preview feature exists by default in Excel’s ribbon, VBA enables you to control it programmatically — meaning you can make it appear automatically at the right time in your workflow.
Benefits of VBA-based Print Preview
- Avoid layout mistakes before printing.
- Standardize page setup for every user.
- Integrate previews into one-click buttons or automated tasks.
- Combine preview and print steps seamlessly in one macro.
- Enable RPA (UiPath) workflows to handle print verification without human input.
When properly implemented, Print Preview becomes not just a visual check — but a controlled stage in your automated reporting process.
✅ Understanding Print Preview in Excel VBA
In VBA, Print Preview is triggered through the PrintPreview method, typically applied to the worksheet object.
ActiveSheet.PrintPreview
This opens Excel’s built-in preview window, allowing users to see exactly what will print.
Unlike PrintOut, this method doesn’t print automatically — it simply pauses until the preview window is closed.
・Syntax Overview
expression.PrintPreview
Where expression represents a Worksheet or Workbook object.
For example:
ActiveSheet.PrintPreview→ previews the active worksheet.Sheets("Report").PrintPreview→ previews a specific sheet.ActiveWorkbook.PrintPreview→ previews all active sheets.
✅ Step 1: Display Basic Print Preview with a Macro
・Create a Simple Macro
- Open the Developer tab → click Visual Basic.
- Insert a new module: Insert → Module.
- Paste the following code:
Sub ShowPreview()
ActiveSheet.PrintPreview
End Sub
- Run the macro (F5) or assign it to a button.
✅ Result: Excel displays a print preview of the active worksheet instantly.
✅ Step 2: Add a Print Preview Button on the Sheet
A physical button makes the feature accessible for all users, even non-technical ones.
・Add the Button
- Go to Developer → Insert → Form Controls → Button.
- Draw it anywhere on the sheet.
- In the dialog “Assign Macro,” select ShowPreview.
- Label it “Print Preview.”
Now, clicking this button will instantly show the Print Preview window for the active sheet.
✅ Step 3: Display Print Preview for a Specific Sheet
If you want to preview a report that always resides on a specific worksheet:
Sub PreviewSpecificSheet()
Sheets("Monthly_Report").PrintPreview
End Sub
✅ Useful when your workbook contains multiple sheets but only one is printable, such as invoices or dashboards.
✅ Step 4: Display Print Preview for Multiple Sheets
Sometimes, reports span across multiple worksheets — for example, summary + detail + chart.
・Preview Multiple Sheets Together
Sub PreviewMultipleSheets()
Sheets(Array("Summary", "Details", "Charts")).PrintPreview
End Sub
✅ Excel will open a combined preview window showing all selected sheets in sequence.
✅ Step 5: Automatically Apply Page Settings Before Preview
Before showing the preview, you can ensure layout consistency.
Sub PreviewWithSetup()
With ActiveSheet.PageSetup
.Orientation = xlLandscape
.PaperSize = xlPaperA4
.FitToPagesWide = 1
.FitToPagesTall = False
.CenterHorizontally = True
.TopMargin = Application.InchesToPoints(0.5)
.BottomMargin = Application.InchesToPoints(0.5)
End With
ActiveSheet.PrintPreview
End Sub
✅ Guarantees that users always see the correct layout before printing — regardless of printer defaults.
✅ Step 6: Preview a Defined Print Area Only
Sometimes, only a part of the worksheet needs to be previewed — such as an invoice or a table region.
・Define and Preview the Print Area
Sub PreviewPrintArea()
ActiveSheet.PageSetup.PrintArea = "$A$1:$G$40"
ActiveSheet.PrintPreview
End Sub
✅ Helps you focus on the essential portion of the sheet, avoiding blank or hidden areas.
✅ Step 7: Add a Confirmation Message Before Preview
To make the user experience friendlier:
Sub ConfirmBeforePreview()
If MsgBox("Would you like to open Print Preview?", vbYesNo + vbQuestion, "Confirm") = vbYes Then
ActiveSheet.PrintPreview
End If
End Sub
✅ Prevents unwanted previews in automated or shared environments.
✅ Step 8: Integrate Preview and Print in One Macro
For business workflows, it’s often practical to show a preview and then ask the user if they’d like to print.
Sub PreviewAndPrint()
ActiveSheet.PrintPreview
If MsgBox("Do you want to print this report?", vbYesNo + vbQuestion) = vbYes Then
ActiveSheet.PrintOut
End If
End Sub
✅ Efficient for front-office or administrative tasks where quick approval is required before printing.
✅ Step 9: Preview Before Exporting to PDF
When you automate PDF creation, showing a preview first ensures the output matches your expectations.
Sub PreviewBeforePDF()
ActiveSheet.PrintPreview
Dim FilePath As String
FilePath = ThisWorkbook.Path & "\PreviewReport_" & Format(Now, "yyyymmdd_hhmmss") & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=FilePath
MsgBox "PDF exported successfully at: " & FilePath
End Sub
✅ Perfect for financial or operational reports that are regularly distributed via email.
✅ Step 10: Customizing Print Preview Buttons for Teams
You can create multiple buttons for different actions:
| Button | Macro | Description |
|---|---|---|
| Preview Current Sheet | ShowPreview | Displays preview only |
| Preview + Print | PreviewAndPrint | Shows preview, then prints |
| Preview with Setup | PreviewWithSetup | Adjusts layout first |
| Preview Multiple Reports | PreviewMultipleSheets | Combines several sheets |
This modular design improves usability across teams.
✅ Step 11: Create a Dynamic Print Preview System for All Sheets
For large workbooks, loop through each worksheet automatically.
Sub PreviewAllSheets()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.PrintPreview
Next ws
End Sub
✅ Gives you complete visual verification for all sheets in sequence.
✅ Step 12: Automatically Trigger Print Preview When Opening the File
For audit reports or invoice templates, you may want the preview to appear as soon as the workbook opens.
Private Sub Workbook_Open()
Sheets("Invoice").PrintPreview
End Sub
✅ Add this to the ThisWorkbook module — it ensures every user sees the preview first thing after opening.
✅ Step 13: Add Print Preview to a Ribbon Button or Shortcut
For professional deployment, connect the macro to Excel’s ribbon.
- Go to File → Options → Customize Ribbon.
- Choose “Macros” from the list on the left.
- Add your Print Preview macro to a custom group.
- Assign an icon (for example, a printer).
✅ Now your Print Preview button is available in every session.
✅ Step 14: Handle Large Files Gracefully
When working with big spreadsheets, Print Preview can take time to load.
You can inform users using the status bar.
Sub PreviewWithStatus()
Application.StatusBar = "Loading Print Preview..."
DoEvents
ActiveSheet.PrintPreview
Application.StatusBar = False
End Sub
✅ Enhances the user experience, especially in corporate reports with heavy formatting.
✅ Step 15: Integrating Print Preview into RPA Workflows
When combined with RPA tools such as UiPath, Print Preview becomes part of a “visual validation” workflow.
For example:
- VBA sets up the report layout.
- VBA triggers
PrintPreview. - UiPath captures a screenshot or confirms layout alignment.
- The bot closes the preview window and proceeds with PDF export.
This hybrid automation allows a balance between accuracy and efficiency.
✅ Step 16: Troubleshooting Print Preview Issues
| Problem | Likely Cause | Solution |
|---|---|---|
| Nothing happens when running macro | Macros disabled | Enable macros or adjust Trust Center settings |
| Preview opens wrong sheet | No sheet reference | Use Sheets("Name").PrintPreview explicitly |
| Layout looks different on different PCs | Different printer defaults | Set .PaperSize, .Margins, and .Orientation in VBA |
| Slow loading preview | Large data ranges or graphics | Clear unused cells and define .PrintArea |
| Headers not repeated | Missing PrintTitleRows | Add .PrintTitleRows = "$1:$1" before preview |
By diagnosing these common issues, your automation remains stable across environments.
✅ Step 17: Real-World Business Use Cases
| Scenario | Benefit |
|---|---|
| Finance Departments | Preview monthly statements to ensure accuracy before printing |
| Sales Teams | Preview client invoices to confirm branding and totals |
| Operations | Preview shipping lists and batch labels |
| HR Departments | Review employee attendance summaries before submission |
| RPA Automation | UiPath uses VBA macros to generate reports and verify layout visually before distribution |
Print Preview adds a verification layer that saves resources and reduces costly misprints.
✅ Step 18: Combining Print Preview with Other VBA Features
You can connect Print Preview to:
- Data validation macros (check missing values before printing)
- Cell protection logic (prevent editing before print)
- Automated footer generation (date/time, user info)
- Conditional formatting for print visibility
This transforms your Excel workbook into a self-contained report generator.
✅ Step 19: Enhancing User Interface for Print Preview
A well-designed button improves engagement:
- Use a rounded rectangle shape labeled “🖨 Preview Report.”
- Color it blue to indicate “review stage.”
- Place it at the top of the report sheet.
- Add tooltips like “Click to review layout before printing.”
- Combine with a “Print Now” button for the final step.
This small UX improvement dramatically boosts usability and professionalism.
✅ Step 20: Full Example – Professional Preview Macro
Here’s a ready-to-use macro combining all key concepts:
Sub ProfessionalPreview()
Dim ans As VbMsgBoxResult
With ActiveSheet.PageSetup
.Orientation = xlLandscape
.FitToPagesWide = 1
.FitToPagesTall = False
.CenterHorizontally = True
.TopMargin = Application.InchesToPoints(0.5)
.BottomMargin = Application.InchesToPoints(0.5)
.LeftMargin = Application.InchesToPoints(0.4)
.RightMargin = Application.InchesToPoints(0.4)
.PrintTitleRows = "$1:$1"
.CenterFooter = "Page &P of &N"
End With
Application.StatusBar = "Preparing Print Preview..."
DoEvents
ActiveSheet.PrintPreview
Application.StatusBar = False
ans = MsgBox("Do you want to print this report?", vbYesNo + vbQuestion, "Confirm Print")
If ans = vbYes Then
ActiveSheet.PrintOut
MsgBox "Printing completed successfully!"
Else
MsgBox "Preview closed without printing."
End If
End Sub
✅ This macro:
- Sets layout automatically
- Displays preview
- Prompts the user to print
- Resets the status bar after completion
Perfect for any corporate report template.
✅ Summary: Master Print Preview Automation in Excel VBA
PrintPreviewprovides a vital confirmation step before printing.- VBA allows you to automate when and how previews appear.
- You can preview single or multiple sheets, specific ranges, or defined areas.
- Combine preview with layout settings to standardize appearance.
- Integrate with UiPath or RPA systems for full report automation.
- Add confirmation, progress messages, and professional buttons for best UX.
By mastering Print Preview in Excel VBA, you bring precision and consistency to every report your team produces.
It’s not just about viewing pages — it’s about building confidence that every printed or exported document looks exactly as intended.
In modern business workflows where time and accuracy are everything, a VBA-powered Print Preview system transforms Excel from a simple spreadsheet into a professional publishing platform.
