Work with the File Name in the Save

Work with the File Name in the Save

Post by David Bass » Wed, 30 Jul 2003 10:02:04


My users want the name of the document file to appear in
the footer whenever they save the document. They do not
want the file name to appear before the document is
saved, therefore, just adding the autotext field is not a
solution. The problem I have is whenever they re-save
the document. The code would add a second instance of
the filename date field. The code I have now completely
fails to put the date field in at all. I need for the
code to not add but update or delete and reinsert the
file name whenever the users save.
Sub FileSave()

ActiveDocument.Save

Dim myrange As Range
Dim aField As Field
Set myrange = ActiveDocument.Sections(1).Footers _
(wdHeaderFooterPrimary).Range
For Each aField In myrange.Fields
aField.Delete
Next aField

Dim myrange1 As Range
Set myrange1 = ActiveDocument.Bookmarks
("FooterFileName").Range
With myrange1
.Fields.Add Range:=myrange, Type:=wdFieldFileName
End With

End Sub

TIA!
david
 
 
 

Work with the File Name in the Save

Post by Doug Robbi » Wed, 30 Jul 2003 11:05:42

Hi David,

If you put the following field construction in the footer of the template,
nothing will appear until the document is saved:

{ IF { SAVEDATE \@ "yyyy" } = "0000" "" { FILENAME } }

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP

 
 
 

Work with the File Name in the Save

Post by David Bass » Wed, 30 Jul 2003 12:03:16

Hi Doug,

Good to see your response. I used your field code and
replaced "0000" with "2003" but the result when I save
the document is "Document7", the default name before the
save. Is there a way to pickup the name the file is
being saved as?

TIA!

david
footer of the template,
newsgroups for the
questions forwarded
consulting basis.
message

in
not
not a
completely
Type:=wdFieldFileName
 
 
 

Work with the File Name in the Save

Post by Doug Robbi » Wed, 30 Jul 2003 18:05:50

i David,

You should leave the "0000" as "0000". If the document has not been saved,
the year of the { SAVEDATE \@ "yyyy" } field will be "0000". If the fields
in the document are updated before the document is saved, the field
construction will not display anything. If you save the document (in any
year other than the year 0, the { SAVEDATE \@ "yyyy" } field will not =
"0000" and then the filename will be displayed by the { FILENAME } field
once the fields in the document are updated.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
"David Bassett" < XXXX@XXXXX.COM > wrote in message
news:064c01c3557d$f4ea3ad0$ XXXX@XXXXX.COM ...