J
Jentimus
Goal: In some lines of a TOC, I want to replace the tab, page number and
paragraph mark with a paragraph mark only. The lines are identified with by
including a specific word (in the example/code below, the identifying word is
'ONE').
For example,
PART ONE TRUST DISTRIBUTION PROVISIONS 1
is replaced by
PART ONE TRUST DISTRIBUTION PROVISIONS
The code below works if the selected text is typed text, but doesn't work if
the selected text is in the Table of Contents field:
Sub test()
' Remove the number after a 'Part' X.
With Selection.Find
.ClearFormatting
.Text = "(ONE )(*)^t[0-9]^13"
With .Replacement
.ClearFormatting
.Text = "\1\2^13"
End With
.Execute Replace:=wdReplaceAll, _
Format:=True, MatchCase:=True, _
MatchWholeWord:=True, MatchWildcards:=True
End With
End Sub
Other text replacement functions work in a selected TOC, but those do not
use Expressions, so maybe that is the issue?
Any advice is appreciated; thanks in advance for your time.
Jen
paragraph mark with a paragraph mark only. The lines are identified with by
including a specific word (in the example/code below, the identifying word is
'ONE').
For example,
PART ONE TRUST DISTRIBUTION PROVISIONS 1
is replaced by
PART ONE TRUST DISTRIBUTION PROVISIONS
The code below works if the selected text is typed text, but doesn't work if
the selected text is in the Table of Contents field:
Sub test()
' Remove the number after a 'Part' X.
With Selection.Find
.ClearFormatting
.Text = "(ONE )(*)^t[0-9]^13"
With .Replacement
.ClearFormatting
.Text = "\1\2^13"
End With
.Execute Replace:=wdReplaceAll, _
Format:=True, MatchCase:=True, _
MatchWholeWord:=True, MatchWildcards:=True
End With
End Sub
Other text replacement functions work in a selected TOC, but those do not
use Expressions, so maybe that is the issue?
Any advice is appreciated; thanks in advance for your time.
Jen