Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing Field links in Word

Status
Not open for further replies.

davefish

Technical User
Jul 26, 2002
169
GB
I'm trying to break a number of field links on a word template prior to saving, but I'm having difficulty finding the code. I've tried recording a macro, but this doesn't capture the event, which is triggered by the document being printed. Can anyone point me in the right direction please.

DaveFish
 
Hi DaveFish,

I'm not sure what you mean when you say it's done automatically when prined. Fields can be updated on printing, but not unlinked unless code is involved.

To unlink fields ...
In code, use [blue]Fields.Unlink[/blue].
Manually use Ctrl+Shift+F9

To update fields ...
In code, use [blue]Fields.Update[/blue].
Manually use F9

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Hi DaveFish,

In vba:
ActiveDocument.Fields.Unlink
will unlink all fields in the body of the document. Different code is needed to process headers, footers, shapes, TOCs etc as well. A fully-fledged macro to do this is:

Sub UnlinkAllFields()
Dim TrkStatus As Boolean ' Track Changes flag
Dim oRange As Word.Range ' All Range objects - includes ranges in the body, headers, footers & shapes
Dim TOC As TableOfContents ' Table of Contents Object
Dim TOA As TableOfAuthorities ' Table of Authorities Object
Dim TOF As TableOfFigures ' Table of Figures Object
With ActiveDocument
' Store current Track Changes status, then switch off
TrkStatus = .TrackRevisions
.TrackRevisions = False
' Loop through all range objects and update
For Each oRange In .StoryRanges
Do
oRange.Fields.Unlink
Set oRange = oRange.NextStoryRange
Loop Until oRange Is Nothing
Next
' Loop through TOCs and update
For Each TOC In .TablesOfContents
TOC.Unlink
Next
' Loop through TOAs and update
For Each TOA In .TablesOfAuthorities
TOA.Unlink
Next
' Loop through TOFs and update
For Each TOF In .TablesOfFigures
TOF.Unlink
Next
' Restore original Track Changes status
.TrackRevisions = TrkStatus
End With
End Sub


Cheers
 
Hi guy's,

Thnaks very much for your suggestions. I need to remove all links of the document so the global ActiveDocument.Fields.Unlink worked fine.

Thanks for your help.

DaveFish
 
Sorry about the additional question, but If I wanted to trigger the ActiveDocument.Field.Unlink command but only after the document is printed, what is the event I should tag. Printout and printpreview just don't do it. Any ideas for Word 97?

DaveFish
 
Hi Dave,

There is no after print event. If you want, you can intercept the print command by writing a macro called FilePrint, and in that macro you can drive the print and then do your unlinking.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top