how to delete specific page breaks via vba

T

TR

I have 400 + large documents that were genereated automatically. They
all have several extra page breaks at specific locations that are
causing blank pages. I already have code that loops a list and opens
each report in turn. I'd like to programmaticlly remove the specific
page breaks. It would take quite awhile to regenerate the docuemnts, so
I am hoping that programmatically modifying them will be faster. I'm
pretty good with Access VBA and VB, but not so familiar with Word and
its manipulation.

I have a bookmark I can go to which is after the pagebreak.
I want to step backwards to the 2nd preceeding page break and remove it.
Any suggestions for doing this? Thus far I have:

Selection.GoTo what:=wdGoToBookmark, Name:="SectionIV_TOC"
Selection.GoToPrevious wdGoToPage
Selection.GoToPrevious wdGoToPage 'this puts me on the page that has the
pagebreak at the bottom that I want to remove

How to select/move to the page break and delete it?
Thanks,
Tom
 
J

Jonathan West

If you want to delete all the manual page breaks, you can do this without
even a macro. Open the Edit Replace dialog. Put "^m" (without the quotes) in
the "Find What" box, leave the "Replace With" box blank, and then click
Replace All.

if you want to automate this as part of a larger procedure, then record a
macro doing that, and include it in your code.
 
T

TR

Hi,
Yes, I needed to automate and run against 400+ already created 200 page
documents, and delete one specific manual page break in each.
Fortunately all docs were created from the same template, and had a bookmark
that was in a consistent position relative to the break.
My solution was a macro to go to the bookmark, set the selection to the end of
the previous section, move back 1 character (which put the selection immediatley
following the break), then do a backspace to remove the page break.
Used a small vb program to loop through all files and run the macro. Worked
great :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top