wild card replacement text in a macro

E

Enda

Hi all,
I would appreciate help the following.

I would like to replace all occurences in a document of the following
line:
\centerline{\includegraphics[ANYTEXT]{ANYTEXT}R

with

\centerline{\includegraphics[ANYTEXT]{ANYTEXT}}R

where R is the EOLF carriage return.

That is, add a closing } to all occurences of the given first line
that ends with only 1 closing }.

My initial attempts at a macro are included below.

Thanks in advance,
Enda


Public Sub repairDoubleBrace()

On Error GoTo ErrHandler

Dim doc As Document
Dim docRange As Range
Dim foundRange As Range

Set doc = ActiveDocument
Set docRange = doc.Content

With docRange
With .Find
.ClearFormatting
.Text = "\\centerline\{\\includegraphics[*]\{*\}^p"
.MatchWildcards = True
With .Replacement
.ClearFormatting
.Text = "\\centerline\{\\includegraphics[*]\{*\}\}^p"
End With
.Execute Replace:=wdReplaceAll

End With
End With

Exit Sub

ErrHandler:
Dim routine As String
routine = "repairCrossReferences "

Select Case Err.Number
Case Else
MsgBox routine _
& vbNewLine & Error(Err) _
& vbNewLine & Err.Number _
& vbNewLine & Err.Description _
& vbNewLine & Err.Source

End Select
End Sub
 
G

Greg

Edna,

I don't know about all of your error handler lines, but
the following may work:

Public Sub repairDoubleBrace()

On Error GoTo ErrHandler

Dim doc As Document
Dim docRange As Range

Set doc = ActiveDocument
Set docRange = doc.Content
With docRange.Find
..ClearFormatting
..Replacement.ClearFormatting
..MatchWildcards = True
..Text = "(\\centerline\{\\includegraphics\[*\]\{*\})(^13)"
..Replacement.Text = "\1}\2"
..Execute Replace:=wdReplaceAll
End With

Exit Sub

ErrHandler:
Dim routine As String
routine = "repairCrossReferences "

Select Case Err.Number
Case Else
MsgBox routine _
& vbNewLine & Error(Err) _
& vbNewLine & Err.Number _
& vbNewLine & Err.Description _
& vbNewLine & Err.Source

End Select
End Sub
 

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