Thank you, Doug.
I think the switch for \a \f4 should be \a \f5. I got the info from
http://office.microsoft.com/en-us/word/HP051861701033.aspx.
\f
4 Maintain the formatting of the source file, if the source file is an
Excel workbook
5 Match the formatting of the destination document, if the source file
is an Excel workbook
I tried f5 and it works. I was using \a \f5 before, but it did not
work. Then I used your method with \* Charformat and it worked.
Thanks again!
However, when I used only \a \f5 \* Charformat, after update, it
created an un-need line break under each of the field. Later, I use
\a \f 4 \r \* Charformat and the extra line break did not come up.
The challege that I am having is that there are many files to be
updated throght this VBA program and each files may contain up to
thousands of different types of links. Right now, I am using Graham's
VBA method (see below) to update the code. I replace "MERGEFORMAT"
with "Charformat", "[space] \r [space]" with "[space] \r \a \f 5
[space]", and "[space] \t [space]" with "[space] \r \a \f 5 [space]".
There may be other varity of switches needed to be replace. I am
trying to get an effective way to do this. If anyone has any idea,
please let me know.
Also, if I have duplicate switch codes in the fields, how would that
impact the update? The reason I asked is that if there are both "\t"
and "\r" in the field, after I run the replacement code, I will get a
pair of "[space] \r \a \f 5 [space]".
In addition, does anyone know why Graham use the For Loop in a
reversed order (and not For i = 1 to ActiveDocument.Fields.Count)?
(Graham's example was found on other thread. The code was kind of
slow. I then discovered that it updates the whole document for every
loop. After I move the .update out side of the loop, it works 100
times faster.)
Anthony
-----------------------------------
Graham's VBA method (with modfication)
-----------------------------------
For i = ActiveDocument.Fields.Count To 1 Step -1
With ActiveDocument.Fields(i)
If .Type = wdFieldTOC Then
If InStr(1, .Code, "MERGEFORMAT") <> 0 Then
..Code.Text = _
Replace(.Code.Text, _
"\* MERGEFORMAT", "")
End If
..Update
End If
End With
Next i