The bold part is easy . Immediately after the line
oRng.Text = rReplacement
add the line
oRng.Bold = True
The other part I am a little unclear about.
The macro finds the two strings correctly in my test document. However as
the macro tests each string separately from start to finish if you then
search for sat L[1 it will find that in both the strings, if the strings
are
unchanged by the earlier replacement. You need to set your table so that
subsequent searches do not clash with those that have already gone.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site
www.gmayor.com
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Spoke too soon...
I am finding some issues where my table has the following values
L[1 STATE [1]
L[10 PROP STREET SUFFIX [10]
So when the macros looks for "L[10" it returns "STATE[1]". In other
words,
it is not looking for an exact match as it is set by the macro
(MatchWholeWord:=True).
can this be fixed?
Also, how can I make the results in 'BOLD'
thanks,
--
EdV
:
You are welcome
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site
www.gmayor.com
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
This is great! I can work with this!
Thank you,
--
EdV
:
The following should work. It uses a two column table, without
blank
rows,
here saved as a document - D:\My Documents\Test\Changes.doc The
document
name is not relevant, as long as you define it in the macro. Put
the
text
to
be found in the first column and the replacement in the second
column
and
run the macro with the document to be edited active.
Sub ReplaceFromTableList()
Dim oChanges As Document, oDoc As Document
Dim oTable As Table
Dim oRng As Range
Dim rFindText As Range, rReplacement As Range
Dim i As Long
Dim sFname As String
sFname = "D:\My Documents\Test\Changes.doc"
Set oDoc = ActiveDocument
Set oRng = oDoc.Range
Set oChanges = Documents.Open(sFname)
Set oTable = oChanges.Tables(1)
oDoc.Activate
For i = 1 To oTable.Rows.Count
Set rFindText = oTable.Cell(i, 1).Range
rFindText.End = rFindText.End - 1
Set rReplacement = oTable.Cell(i, 2).Range
rReplacement.End = rReplacement.End - 1
With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(findText:=rFindText, _
MatchWholeWord:=True, _
MatchWildcards:=False, _
Forward:=True, _
Wrap:=wdFindContinue) = True
oRng.Text = rReplacement
Loop
End With
Next i
oChanges.Close wdDoNotSaveChanges
End Sub
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site
www.gmayor.com
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
message
Hello,
I need a macro for a .doc that will find certain text and replace
it
with
its corresponding value from a table of values.
Examples:
Text = s[32] cross reference "Record Name"
Text =s[33] cross reference "Record Address"
My table has about 190 record names which I need to replace
everytime
the
field "Code" is found. In the example above, s[32] will be
replace
by
"record
name". can someone assist?
Thanks,
--
EdV
.
.
.