How do I remove a section break from a document?

R

Robin Tucker

Hi,


I'm trying to split my document up into new documents, one for each section
in the original master document. To do this, I am more or less executing
the following code:

' Create a new document.

Dim theNewDocument As Word.Document =
m_WordApplication.Documents.Add(Visible:=True)

' Add the new document to the list of documents we should keep track of.

m_Sections.Add(theNewDocument)

' Get the current section.

theSection = m_LoadedDocument.Sections.Item(Index + 1)

' Now copy the section into the new document.

theRange = theSection.Range.FormattedText

' Copy across.

theNewDocument.Range.FormattedText = theRange

This is all well and good. Consider a master document with 2 sections. In
this case, the second (last) section is cut and copied correctly into the
new document, however, the first section when copied into the new document
still contains the section break at the end of it. So I am having to write:

' Got more than one section?

If theNewDocument.Sections.Count > 1 Then

' Somehow remove all section breaks from the document

End If

Any ideas on how to remove this section break?

Thanks,



Robin
 
F

Filips Benoit

Robin !

The members of the Sections-class has no delete-event. ( see objectbrowser)
So I have no answer for the moment.

Filips Benoit
 
D

Doug Robbins

Use a method similar to that in the following macro:

Sub splitter()

' splitter Macro

' Macro created by Doug Robbins to save each letter created by a mailmerge
as a separate file.

Dim i As Long, Source as Document, Target as Document, Letter as Range
Set Source = ActiveDocument
For i = 1 to Source.Sections.Count
Set Letter = Source.Sections(i).Range
Letter.End=Letter.End-1
Set Target = Documents.Add
Target.Range=Letter
Target.SaveAs FileName:="Letter" & i
Target.Close
Next i

End Sub


--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
F

Filips Benoit

You can use the Find.Replacement
Try i manualy and record the code.
I gives this code!


Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^b"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
 

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