Break all links on autoclose

K

killajoules

Hi, I have a Word document linked to an Excel model.

I use the following macro to automatically break all the links in th
document when the file is closed. Unfortunately, it is also stoppin
the table of contents from being updatable. Is it possible so tha
only the links in the body and footers is broken, and the page number
and the table of contents remain the same? Thanks in advance,

Sub AutoClose()

' AutoClose Macro
'
With ActiveDocument.Range.Fields
.Unlink
Dim oField As Field
Dim oSection As Section
Dim oHeader As HeaderFooter
Dim oFooter As HeaderFooter
For Each oSection In ActiveDocument.Sections
For Each oHeader In oSection.Headers
If oHeader.Exists Then
For Each oField In oHeader.Range.Fields
oField.Unlink
Next oField
End If
Next oHeader
For Each oFooter In oSection.Footers
If oFooter.Exists Then
For Each oField In oFooter.Range.Fields
oField.Unlink
Next oField
End If
Next oFooter
Next oSection
End With

End Su
 

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