#  Other Applications & Softwares  > Word Formatting & General >  >  Deleting page in word with VBA

## sperry2565

Hopefully this is an appropriate place to ask this....

I know you can't delete a page in word like you can delete a sheet in excel, so I am stuck.  I am creating code to insert a "this page intentionally left blank."  which was the easy part, what I'm struggling with is creating code before that to check that those pages don't already exist and if they do, to remove them if content has been added to the page.  Essentially if an even page that had this phrase on it is now moved to an odd page, I need to remove the page.

It needs to find the phrase then check to see if the page is even or odd.  If it's even, leave it, if it's odd it needs to delete any and all space including the phrase and the page break from the previous page (replaced by the section break from the page that had the phrase on it).

I hope that's clear enough?  I attached a sample document and some code....any help would be greatly appreciated.

test.docm

----------


## sperry2565

Anyone?

Even a "You're crazy, this won't work" would be okay...then I could move on :p

Also, I know that there aren't any "Sections" in my example, I just copied the code from the original document into an example I could share...but I hope you get what I'm trying to explain....

----------


## macropod

Yes, it's possible to specify and delete a page. However, I'd suggest an entirely different approach:

Fields coded as:
{IF{=MOD({PAGE},2)}= 1 {QUOTE 12}}
and
{IF{=MOD({PAGE},2)}= 1 "{QUOTE 12}¶
This page intentionally left blank¶
"}
respectively, will automatically insert a blank page if the page on which they occur is an odd-numbered one.

To get the same effect for an even-numbered page, change the '1' to '0'.

Such a field would be used immediately before a 'Next Page' Section break.

With such a field, you won't have to worry about whether editing changes the pagination - the field will conditionally insert/delete the blank page on an as-required basis, either at print time or if you use Ctrl-A, F9 to update the document.

*Note*: The field brace pairs (i.e. '{ }') for the above example are created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac); you can't simply type them or copy & paste them from this message. Nor is it practicable to add them via any of the standard Word dialogues. The spaces represented in the field construction are all required. Instead of the ¶, you should use real line/paragraph breaks.

----------


## sperry2565

So the user would need to put this on each page that contains a "Section Break (Next Page)"?  I was writing the Macro so that I could send it to fellow coworkers and they could simply click and button and it would save time while creating or editing.

----------


## macropod

Yes, though if you don't want the 'This page intentionally left blank' message, you could use just odd or even Section breaks.

As for expediting, the fields could be inserted via a macro. The advantage of the field approach, of course, is that once they're set up, it doesn't matter if subsequent edits or a change in printers affects the pagination.

----------

