I have a document with links to a database and wish to break these links when the document is closed. I do this using the following code:_
Private Sub Document_Close()
If ActiveDocument.Name <> "Test.doc" Then
ActiveDocument.Fields.Unlink
End Sub
However, I wish to preserve one link, namely {FILENAME}. My code for this is :-
ActiveDocument.Tables(9).Cell(1, 2).Range.Select
Selection.Delete
" This gets rid of any text in the cell"
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"FILENAME ", PreserveFormatting:=True
ActiveDocument.Save
This works fine, but as the original template has many tables, some deleted by the user in the course of setting the document up, I cannot guarantee a reference to the table number. I've tried bookmarking the tables with little success. Can anyone steer me in the right direction??
Rgs
Davefish
Private Sub Document_Close()
If ActiveDocument.Name <> "Test.doc" Then
ActiveDocument.Fields.Unlink
End Sub
However, I wish to preserve one link, namely {FILENAME}. My code for this is :-
ActiveDocument.Tables(9).Cell(1, 2).Range.Select
Selection.Delete
" This gets rid of any text in the cell"
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"FILENAME ", PreserveFormatting:=True
ActiveDocument.Save
This works fine, but as the original template has many tables, some deleted by the user in the course of setting the document up, I cannot guarantee a reference to the table number. I've tried bookmarking the tables with little success. Can anyone steer me in the right direction??
Rgs
Davefish