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!

Copying data to cell in different tables

Status
Not open for further replies.

davefish

Technical User
Jul 26, 2002
169
GB
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top