Delete Section Breaks to End of Document

L

LDMueller

Hello,

We have Word 2003 and I need to search for the word "DocumentTag" and from
this word (or point forward) I need to delete all section breaks to the end
of the document. I tried a search and replace, but it deletes the section
breaks prior to the word "DocumentTag" as well and this won't work for me.

Thanks!
 
J

Jonathan West

LDMueller said:
Hello,

We have Word 2003 and I need to search for the word "DocumentTag" and from
this word (or point forward) I need to delete all section breaks to the
end
of the document. I tried a search and replace, but it deletes the section
breaks prior to the word "DocumentTag" as well and this won't work for me.

Show us the relevant part of code you have so far. Its probably a fairly
simple change needed, but its much easier to describe the change if we can
see what you have already.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
L

LDMueller

Note is these examples the word I'm searching for is "StartMatterTag" instead
of "DocumentTag".

Sub Macro3()
Selection.Find.ClearFormatting
With Selection.Find
.Text = "StartMatterTag"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Selection.HomeKey Unit:=wdLine
Selection.Extend
Selection.EndKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^b"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub


I also tried looping this, but it didn't work either.

Sub Macro99()
Do While Selection.Find.Execute(FindText:="^b", MatchWildcards:=False, _
Wrap:=wdFindAsk, Forward:=True) = True

Selection.Find.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
Selection.Delete Unit:=wdCharacter, Count:=1

Loop

End Sub
 
H

Helmut Weber

Hi LDMueller,

how about this one:

Sub test1()
Dim rdcm As Range
Set rdcm = ActiveDocument.Range
With rdcm.Find
.Text = "StartMatterTag"
If .Execute Then
rdcm.Delete
rdcm.End = ActiveDocument.Range.End
With rdcm.Find
.Text = chr(12)
.Replacement.Text = ""
.Execute Replace:=wdReplaceAll
End With
End If
End With
End Sub


--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
L

LDMueller

Helmut,

It's perfect with the exception it is also deleting my tag (e.g.
"StartMatterTag") and I need it for other functions.

Thanks, Leigh
 
H

Helmut Weber

Hi LDMueller,

I thought, that's what you wanted to do.

Sub test1()
Dim rdcm As Range
Set rdcm = ActiveDocument.Range
With rdcm.Find
.Text = "StartMatterTag"
If .Execute Then
rdcm.End = ActiveDocument.Range.End
With rdcm.Find
.Text = chr(12)
.Replacement.Text = ""
.Execute Replace:=wdReplaceAll
End With
End If
End With
End Sub

If you like, send me a mail
with information about your name,
where you are etc.
It's just a hobby of mine,
to find out about names and there stories. ;-)



--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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