I have a word doc with nine tables, some of which are used to show a reference to the filename. As there are other links to a database which need to be brokenon saving/printing, I have done this programatically, but need to retain the filename field in table 1, 3 & 7.
No problem if the number of tables were constant, but users have the ability to delete and add accordingly. I'm also having problems with bookmarks, as the originals documents were in word 97 and we're now on word 2003. It seems I can bookmark ok in 2003!
Here's my code Which deletes the bookmarks in 97 but not 2003??
Can anyone help?
CodMAn
Private Sub Document_Close()
If ActiveDocument.Name <> "Q452 Rev 0 master.doc" Then
ActiveDocument.Fields.Unlink
ActiveDocument.Tables(1).Cell(1, 3).Range.Select
Selection.Delete
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"FILENAME ", PreserveFormatting:=True
Selection.GoTo What:=wdGoToBookmark, Name:="AA"
Selection.Find.ClearFormatting
Selection.MoveRight Unit:=wdCharacter, Count:=20, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"FILENAME ", PreserveFormatting:=True
Selection.GoTo What:=wdGoToBookmark, Name:="BB"
Selection.Find.ClearFormatting
Selection.MoveRight Unit:=wdCharacter, Count:=20, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"FILENAME ", PreserveFormatting:=True
ActiveDocument.Save
End If
End Sub
No problem if the number of tables were constant, but users have the ability to delete and add accordingly. I'm also having problems with bookmarks, as the originals documents were in word 97 and we're now on word 2003. It seems I can bookmark ok in 2003!
Here's my code Which deletes the bookmarks in 97 but not 2003??
Can anyone help?
CodMAn
Private Sub Document_Close()
If ActiveDocument.Name <> "Q452 Rev 0 master.doc" Then
ActiveDocument.Fields.Unlink
ActiveDocument.Tables(1).Cell(1, 3).Range.Select
Selection.Delete
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"FILENAME ", PreserveFormatting:=True
Selection.GoTo What:=wdGoToBookmark, Name:="AA"
Selection.Find.ClearFormatting
Selection.MoveRight Unit:=wdCharacter, Count:=20, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"FILENAME ", PreserveFormatting:=True
Selection.GoTo What:=wdGoToBookmark, Name:="BB"
Selection.Find.ClearFormatting
Selection.MoveRight Unit:=wdCharacter, Count:=20, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"FILENAME ", PreserveFormatting:=True
ActiveDocument.Save
End If
End Sub