Work with the File Name in the Save

D

David Bassett

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
 
D

Doug Robbins - Word MVP

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
 
D

David Bassett

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
 
D

Doug Robbins - Word MVP

Hi 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top