To delete all page breaks in Excel using VBA, use the ResetAllPageBreaks method on the target worksheet. This removes both manual and automatic page breaks, ensuring consistent printing layout. No external tools or add-ins are required—just Excel with VBA enabled.

What You'll Need

  • Microsoft Excel (2010 or later; works in 365, 2016, 2019, and 2021)
  • A workbook with at least one worksheet containing page breaks
  • VBA enabled (macro settings must allow code execution)
  • Basic familiarity with the VBA editor (Alt+F11)

Step-by-Step

  1. Open your Excel workbook and ensure it is saved in a macro-enabled format (.xlsm) if you plan to keep the code. If the file is .xlsx, save a copy as .xlsm before proceeding.
  2. Press Alt + F11 to open the Visual Basic for Applications (VBA) editor.
  3. In the Project Explorer window (top-left), locate your workbook. If the Project Explorer is hidden, press Ctrl + R to display it.
  4. Right-click on the workbook name or any existing module, then choose Insert > Module to create a new blank module.
  5. Copy and paste the following VBA code into the module window:
    Sub DeleteAllPageBreaks()
        Dim ws As Worksheet
        For Each ws In ActiveWorkbook.Worksheets
            ws.ResetAllPageBreaks
        Next ws
    End Sub
    This loop iterates through every worksheet in the active workbook and removes all page breaks.
  6. Press F5 while in the VBA editor to run the macro, or return to Excel and run it via Alt + F8, selecting DeleteAllPageBreaks and clicking Run.
  7. Verify success by switching to Page Layout view (View > Page Layout). You should see no horizontal or vertical break lines (dashed blue lines) between pages. Alternatively, go to File > Print to preview the layout.

Common Mistakes

  • Running the macro on the wrong workbook: Ensure the correct workbook is active when running the code. The macro operates on ActiveWorkbook, not a specific saved file.
  • Macro security blocking execution: If Excel disables macros, the code won’t run. Go to File > Options > Trust Center > Trust Center Settings > Macro Settings, and select Enable all macros (temporarily, for testing).
  • Using ActiveWorksheet instead of looping: A common error is writing code like ActiveSheet.ResetAllPageBreaks without looping, which only clears breaks on the currently selected sheet—not all sheets.
  • Confusing manual and automatic breaks: Manual page breaks (inserted via Page Break Preview) behave differently than automatic ones. ResetAllPageBreaks clears both, but only if applied correctly.

Tips

  • Backup first: Save a copy of your workbook before running the macro. Though safe, unexpected corruption can occur in large or complex files.
  • Target specific sheets only: To delete breaks on selected sheets, replace the loop with explicit sheet references, e.g., Worksheets("Sheet1").ResetAllPageBreaks.
  • Combine with print settings: After clearing breaks, use ws.PageSetup.PrintArea = "" to remove print areas if needed for full-page layout control.
  • Use Page Layout view to verify: Dashed blue lines indicate page breaks. Their absence confirms success. Print Preview (Ctrl+P) also shows this visually.
  • Automate with a button: Insert a form control button (Developer tab > Insert > Button), assign the macro, and click it for one-click cleanup.

Troubleshooting

If the macro doesn’t remove page breaks, follow these steps:

  1. Check if the macro ran: Look for a blank status bar after running. If Excel shows no error but breaks remain, ensure the code executed—add MsgBox "Page breaks reset on " & ws.Name inside the loop for confirmation.
  2. Verify macro security: Go to File > Options > Trust Center > Macro Settings. Confirm macros are not disabled. If Disable all macros without notification is selected, enable them temporarily.
  3. Test on a new workbook: Create a blank workbook, insert a manual page break (Page Layout > Breaks > Insert Page Break), then run the macro. If it works here, the issue is file-specific (e.g., protected sheets).
  4. Check for sheet protection: If a worksheet is protected, ResetAllPageBreaks may fail silently. Unprotect sheets first (Review > Unprotect Sheet), then run the macro. To automate this, modify the code:
    Sub DeleteAllPageBreaksWithUnprotect()
        Dim ws As Worksheet
        For Each ws In ActiveWorkbook.Worksheets
            ws.Unprotect Password:="" 'leave quotes empty if no password
            ws.ResetAllPageBreaks
        Next ws
    End Sub
    Replace "" with your actual password if protected.
  5. Restart Excel: Rarely, Excel’s VBA engine locks up. Close all Excel windows, reopen, and retry.

Frequently Asked Questions

Does ResetAllPageBreaks affect page setup settings like margins or orientation?

No. It only clears horizontal and vertical break lines. Page setup properties (e.g., PageSetup.Orientation, PageSetup.Zoom) remain unchanged.

Can I delete only manual page breaks and keep automatic ones?

Not directly with a single method. Use ws.HPageBreaks.Count and ws.VPageBreaks.Count to identify manual breaks, then remove them individually via ws.HPageBreaks(i).Delete or ws.VPageBreaks(i).Delete in a loop. Automatic breaks are recalculated by Excel and cannot be preserved while deleting manual ones.

Why does the macro run but page breaks reappear after saving and reopening?

Excel automatically reinserts page breaks based on paper size, scale, and print area when the workbook is opened. To prevent this, ensure no print areas are set (ws.PageSetup.PrintArea = "") and check Page Layout > Page Setup > Scale for consistent settings.

Will this work on protected workbooks or shared workbooks?

On shared workbooks (File > Info > Share Workbook), page break operations may be restricted. Unshare the workbook first (File > Info > Collaborate > Stop Sharing). For password-protected sheets, unprotect them before running the macro or include unprotect logic in the code.

Does this clear page breaks in charts or pivot tables?

No. Page breaks apply only to regular worksheet grids. Charts and pivot tables don’t have page break lines; their layout is controlled via chart sheet settings or embedded object sizing.

Can I undo this action after running the macro?

Yes—press Ctrl + Z immediately after running if you’re still in Excel. However, once the workbook is closed and reopened, Excel recalculates automatic breaks, so true reversal requires reinserting manual breaks manually or via VBA.