Macro to delete breaks

R

Robert

Is there a way to delete all section breaks and page
breaks from documents with a macro and empty all the
contents of the headers and footers? The breaks can be
anywhere and the documents vary from a few to many pages.
Thanks for any help.
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Robert,

You can use Edit>Replace to remove the Section Breaks and the Page Breaks by
putting ^b in the Find what box for the former and ^m in that box for the
latter. If you turn on the macro recorder while performing those actions,
it will produce the code for you.

To use code to delete the headers and footers, after getting rid of all of
the section breaks so that there would then only be one section in the
document, use

With ActiveDocument.Sections(1)
.Headers(wdHeaderFooterFirstPage).Range.Delete
.Headers(wdHeaderFooterPrimary).Range.Delete
.Footers(wdHeaderFooterFirstPage).Range.Delete
.Footers(wdHeaderFooterPrimary).Range.Delete
End With


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 
R

Robert

Thanks. That works well except the footers on the even
pages aren't deleted. The documents have headers and
footers for both even and odd pages.
 
J

Jay Freedman

Hi, Robert,

That just means you need to throw two more lines in to join the four
that are already between the With and End With statements:

.Headers(wdHeaderFooterEvenPages).Range.Delete
.Footers(wdHeaderFooterEvenPages).Range.Delete
 
M

marmendariz

Hello,

I tried but couldn't use the find and replace feature to delete al
section breaks- when I entered ^b to search for the section breaks, i
said it couldn't find any. I use Word XP. I desperately need help
Thank
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Are you sure that you have not checked the Use wildcards box. It must be
unchecked.

If you run a macro containing the following code, what does the message tell
you?

MsgBox ActiveDocument.Sections.Count

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 
T

Tonya Marshall

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACTERS FROM EMAIL ADDRESS
wrote:
Are you sure that you have not checked the Use wildcards box. It must be
unchecked.

If you run a macro containing the following code, what does the message tell
you?

MsgBox ActiveDocument.Sections.Count
When I was working on my WP to WD label conversion templates I had the
same trouble. Searches couldn't find the breaks. Finally, after many
fits and starts, Dave Rado wrote this macro for me and it removed the
section breaks between the label tables:

Dim i As Long
For i = ActiveDocument.Sections.Count - 1 To 1 Step -1
ActiveDocument.Sections(i).Range.Characters.Last.Select
Selection.Delete
Next i
Application.ScreenUpdating = True
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting

HTH
 

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