Delete section breaks without using replace

Z

zkid

I have a merged document in a table format. So, once merged, there is a
section break in between between each row of the table. There are over 500
records being merged, so it is not possible to create a table with all
possible <next record> fields.

For some reason, using the replace feature will not touch the section
breaks. If I search for each one, and then use selection.delete, that works
fine. However, this process is excrutiatingly slow in large documents.

Does anyone know of a way to programmically iterate each section break as an
object? Something like:

For Each sec In ActiveDocument.Sections
sec.Delete
Next sec

I don't want to delete the section range - just the section break itself.

Thanks so much.
 
J

Jezebel

Interesting problem. Here's a quick-and-dirty fix:

Dim pTable As Word.Table

For Each pTable In ActiveDocument.Tables
pTable.Select
With Selection
.Collapse
.TypeBackspace
.Delete Unit:=wdCharacter, Count:=1
End With
Next
 
Z

zkid

Thanks for your response, Jezebel. Unfortunately, your code takes the same
amount of time as mine, as well as the following code I found from Doug
Robbins:

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="^p^b", Wrap:=wdFindContinue, _
Forward:=True) = True
Selection.Delete
Loop
End With

Any other ideas?
 
Z

zkid

Hey, I just figured out how to get around the whole mess.

To do it programmically, just set the mail merge primary document as a
catalog type.

ActiveDocument.MailMerge.MainDocumentType = wdCatalog

Then when the file is merged, none of the section breaks show up!
 
G

Greg Maxey

How about:

Sub Test()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "^b"
While .Execute
oRng.Delete
Wend
End With
End Sub
 
J

Jean-Guy Marcil

zkid was telling us:
zkid nous racontait que :
Hey Greg, I lied. Your code does run a lot faster. Thanks!

Once again, the power of the Range object prevailed over the Selection
object! :)

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
G

Greg Maxey

I always try range first and keep at it until I am a babbling lunatic.
If that occurs I then shift to selection to see it if will work ;-)
 

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