How to Delete a Blank Word Page in VBA

Save

While Microsoft Word doesn't have a button or tool for every possible scenario, you can create user-defined macros, pieces of executable code, using Visual Basic for Applications (VBA). Macros can tailor Word to fit your needs. For example, if you have a document interspersed with blank pages, it might seem like your only option is to manually go through the document and delete the offending pages. There is another option: use a VBA macro to do the leg work for you.

Things You'll Need

  • Word 2010
  • Press "Alt" and "F11" together in the Word document you want to remove blanks from to open the Visual Basic Editor (VBE).

  • Click "Insert" and then click "Module" to insert a blank module window.

  • Cut and paste the following code into the blank module window:

    Public Sub DeleteBlankPage()

    Selection.GoTo What:=wdGoToBookmark, Name:="\page"

    If isBlankSelection Then

    Selection.Delete

    End If

    End Sub

    Public Function BlankPageSelection()

    For Each c In Selection.Characters

    If (c <> vbCr And c <> vbTab And c <> vbFormFeed And c <> " ") Then

    BlankPageSelection = False

    Exit Function

    End If

    Next

    BlankPageSelection = True

    End Function

  • Press "F5" to run the routine and delete the blank pages from your document.

Tips & Warnings

  • You can use the same code at a later date: The code will save along with your Word document. Open the VBE and then click "DeleteBlankPage" from the left hand sidebar. Press "F5" to run the routine.

References

Promoted By Zergnet

Comments

Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

M
Is DIY in your DNA? Become part of our maker community.
Submit Your Work!