TOC - "Preserve formatting during updates"

R

Ronny

Hello.

I have a problems when trying to update the TOC from VBA (and manually).
“Preserve formatting during updates†is set, and is causing the problem.
Cause when I remove it manually I can update manually. But the next time I
open the doc this setting is back. How can I control this from VBA? (I want
to turn it off)

Ronny
 
G

Graham Mayor

The Preserve formatting during updates check box in the fields dialog is
always set by default. However if you insert a TOC field from Insert >
Reference > Index & Tables, the Mergeformat switch is not added. I see no
obvious reason why simply updating the TOC field would add such a switch, so
I guess the answer must lie in your code. What exactly are you doing with
the TOC field from vba?

The following will remove a \* MERGEFORMAT switch from a TOC field that
should find itself with one and update the field

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


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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