Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to Select Through 1st Section Break in Word

Status
Not open for further replies.

clhare

Technical User
May 29, 2003
118
US
I'm trying to use a macro to clean up a document that will start out with a varying number of paragraph marks followed by a section break and two more paragraph marks before the text starts.

Is there a way to select starting with the 2nd paragraph mark in the document and including the first paragraph mark after the first section break and then delete that selection? The number of paragraph marks before the first section break will vary.

Example:

[paragraph mark]
[paragraph mark] <-- delete starts with this one
[paragraph mark] <-- delete
[paragraph mark] <-- delete
. <-- delete
. <-- delete
[section break] <-- delete
[paragraph mark] <-- delete includes this one
[paragraph mark]
Text starts here...


Any help is greatly appreciated!

Cheryl
 
How do I attach a file?

Any help is greatly appreciated!

Cheryl
 
How do I tell if the section break is part of the paragraph? "

A Section break is never part of a paragraph.

With Show/Hide on, you see the paragraph mark followed by:

Section Break (Next Page)

if it is indeed a NextPage section break.

Since I have asked repeatedly for you to post your actual code, and what the situation actually IS - "I have footers that I want to keep linked to previous, and headers I do NOT want to keep linked" (for example) - and you are not posting the code, I do not see how I can help further.

Tony should be able to do so.

Gerry
 
I mentioned previously that the only code I have so far is yours:

Code:
Dim r As Range
Set r = ActiveDocument.Range( _
      Start:=ActiveDocument.Sections(1).Range _
      .Paragraphs(2).Range.Start, _
      End:=ActiveDocument.Sections(2).Range _
      .Paragraphs(2).Range.Start)
r.Delete

I would like to post a sample file, but I can't figure out how to do that without having to sign up for something.

Any help is greatly appreciated!

Cheryl
 
I think the easiest thing to do in this case is just to unlink the headers and footers in Section 2 - and Word should copy them from Section 1 - before the delete. Just put this before Gerry's code that you already have:

Code:
[blue]    Dim HF As HeaderFooter
    For Each HF In ActiveDocument.Sections(2).Headers
        HF.LinkToPrevious = False
    Next HF
    For Each HF In ActiveDocument.Sections(2).Footers
        HF.LinkToPrevious = False
    Next HF[/blue]

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
That's perfect! Exactly what I needed it to do. Thanks you all so much for your help!

Here's my final macro:

Code:
Sub RemoveFirstSection()

Dim R As Range
Dim HF As HeaderFooter

' Unlink all headers and footers in section 2 from previous section
For Each HF In ActiveDocument.Sections(2).Headers
    HF.LinkToPrevious = False
Next HF
For Each HF In ActiveDocument.Sections(2).Footers
    HF.LinkToPrevious = False
Next HF

' Then remove any extra paragraph marks in section 1, keeping only
' the first one and also removing the first section break
Set R = ActiveDocument.Range( _
    Start:=ActiveDocument.Sections(1).Range _
    .Paragraphs(2).Range.Start, _
    End:=ActiveDocument.Sections(2).Range _
    .Paragraphs(2).Range.Start)
R.Delete

End Sub

Any help is greatly appreciated!

Cheryl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top