cancel
Showing results for 
Search instead for 
Did you mean: 

Deleting Blank Pages in Word via Macro

ErjolaMema
Level 5

Hello everyone!

While hoping you all are okay, I want to make a question if someone can help me how to delete the blank pages in Word via Macro .

Thank You,

Erjola



------------------------------
Erjola Mema
------------------------------
8 REPLIES 8

PabloSarabia
Level 11
Hi!

Use this link: https://social.msdn.microsoft.com/Forums/en-US/9837256a-be38-4516-a08d-ab48e9c076f2/macro-to-remove-all-the-blank-pages-in-the-document?forum=worddev

Here is the code that you need to use:

Sub Demo()
    With ActiveDocument.Content.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = "^12[^12^13 ]{1,}"
        .Replacement.Text = "^12"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchWildcards = True
        .Execute Replace:=wdReplaceAll
    End With
End Sub


Hope this helps you

Bye 🙂

------------------------------
Pablo Sarabia
Programmer
Altamira AM
------------------------------

Hi Pablo and thank you for your answer but I dont't know why it didn't work



------------------------------
Erjola Mema
------------------------------

Hi,

Try with this other script. It only deletes paragraphs. 

Sub Demo()
    Dim par As Paragraph
For Each par In ActiveDocument.Content.Paragraphs
If Len(par.Range.Text) <= 1 Then
par.Range.Delete
End If
Next par
End Sub

I try with empty pages at the end of the document and in the middle and works correctly.

Hope with this is done.


Bye 🙂

------------------------------
Pablo Sarabia
Programmer
Altamira AM
------------------------------

PabloSarabia
Level 11
Hi,

How are you trying the macro? I use a common form with a button to test it.

Did you save the document as .docm?

I try it in a document with footer and header and works.

Could you share a copy of the document just to test it?



Bye 🙂

------------------------------
Pablo Sarabia
Programmer
Altamira AM
------------------------------

The word doc file has the format .docx

This is the Word Doc

------------------------------
Erjola Mema
------------------------------

Hi,

Let's try with this! I make another Word for you. (Unzip the attached file)

The main problem is that you don't have the headers and footer with the Word function for this. I put in the file a header and footer, just change it.

If you open the list of Macros ([ALT] + F8) you may see "RemoveBlankPages" macro, execute it when you want to remove blank pages.


Hope this helps you


Bye 🙂

------------------------------
Pablo Sarabia
Programmer
Altamira AM
------------------------------

the point is that  "the header and footer" are putted also with macro code. The A3 format is putted also with macro .

This Is the reason I could't find a code for deleting blank pages.



------------------------------
Erjola Mema
------------------------------