Home |
Search |
Today's Posts |
#1
|
|||
|
|||
automatically update inserted file name
The filename has been inserted into a document. I want the filename to update
automatically when saved as another name. Is this possible? |
#2
|
|||
|
|||
Not without putting a macro into your file. If the field is in a
header/footer, though, it will be updated when you print or do a print preview. -- Charles Kenyon Word New User FAQ & Web Directory: http://addbalance.com/word Intermediate User's Guide to Microsoft Word (supplemented version of Microsoft's Legal Users' Guide) http://addbalance.com/usersguide See also the MVP FAQ: http://www.mvps.org/word which is awesome! --------- --------- --------- --------- --------- --------- This message is posted to a newsgroup. Please post replies and questions to the newsgroup so that others can learn from my ignorance and your wisdom. "Milton Ross" Milton wrote in message ... The filename has been inserted into a document. I want the filename to update automatically when saved as another name. Is this possible? |
#3
|
|||
|
|||
Milton
See: http://gregmaxey.mvps.org/File_Name_And_Path.htm -- Greg Maxey/Word MVP A Peer in Peer to Peer Support Milton Ross wrote: The filename has been inserted into a document. I want the filename to update automatically when saved as another name. Is this possible? |
#4
|
|||
|
|||
Greg, I made a couple of modifications to your macro because I sometimes use
fields like Fill-In fields that I do _not_ want to update. My revision is below. Option Explicit Sub FileSaveAs() ' Based on macro shown in Greg Maxey's page at ' http://gregmaxey.mvps.org/File_Name_And_Path.htm ' ' Displays filename and path in document's title bar when saved using Save As ' Also updates filename fields in document ' Dialogs(wdDialogFileSaveAs).Show System.Cursor = wdCursorNormal ActiveWindow.Caption = ActiveDocument.FullName Dim oStory As Range Dim oField As Field For Each oStory In ActiveDocument.StoryRanges ' oStory.Fields.Update ' replace this with the following For-Next loop For Each oField In oStory.Fields If oField.Type = wdFieldFileName Then oField.Update End If Next oField If oStory.StoryType wdMainTextStory Then While Not (oStory.NextStoryRange Is Nothing) Set oStory = oStory.NextStoryRange oStory.Fields.Update Wend End If Next oStory Set oField = Nothing Set oStory = Nothing ActiveDocument.Save ' Saves document with updated field(s) End Sub In my limited testing, it seems to work. I also added the final save command. Of course, in a document with lots of fields my changes are going to make the macro take a more time, I expect. -- Charles Kenyon Word New User FAQ & Web Directory: http://addbalance.com/word Intermediate User's Guide to Microsoft Word (supplemented version of Microsoft's Legal Users' Guide) http://addbalance.com/usersguide See also the MVP FAQ: http://www.mvps.org/word which is awesome! --------- --------- --------- --------- --------- --------- This message is posted to a newsgroup. Please post replies and questions to the newsgroup so that others can learn from my ignorance and your wisdom. "Greg Maxey" wrote in message ... Milton See: http://gregmaxey.mvps.org/File_Name_And_Path.htm -- Greg Maxey/Word MVP A Peer in Peer to Peer Support Milton Ross wrote: The filename has been inserted into a document. I want the filename to update automatically when saved as another name. Is this possible? |
#5
|
|||
|
|||
Because I don't like to mess with normal.dot and couldn't figure out how to
do a global pseudo AutoOpen in a different global template, I added the following intercept to my global. It gives the filename and path on a document save. Sub FileSave() ' Based on macro shown in Greg Maxey's page at ' http://gregmaxey.mvps.org/File_Name_And_Path.htm ' ' Displays filename and path in document's title bar when saved using Save ' Also updates filename fields in document ' ActiveDocument.Save System.Cursor = wdCursorNormal ActiveWindow.Caption = ActiveDocument.FullName Dim oStory As Range Dim oField As Field For Each oStory In ActiveDocument.StoryRanges ' oStory.Fields.Update ' replace this with the following For-Next loop For Each oField In oStory.Fields If oField.Type = wdFieldFileName Then oField.Update End If Next oField If oStory.StoryType wdMainTextStory Then While Not (oStory.NextStoryRange Is Nothing) Set oStory = oStory.NextStoryRange oStory.Fields.Update Wend End If Next oStory Set oField = Nothing Set oStory = Nothing ActiveDocument.Save ' Saves document with updated field(s) End Sub -- Charles Kenyon Word New User FAQ & Web Directory: http://addbalance.com/word Intermediate User's Guide to Microsoft Word (supplemented version of Microsoft's Legal Users' Guide) http://addbalance.com/usersguide See also the MVP FAQ: http://www.mvps.org/word which is awesome! --------- --------- --------- --------- --------- --------- This message is posted to a newsgroup. Please post replies and questions to the newsgroup so that others can learn from my ignorance and your wisdom. "Charles Kenyon" wrote in message ... Greg, I made a couple of modifications to your macro because I sometimes use fields like Fill-In fields that I do _not_ want to update. My revision is below. Option Explicit Sub FileSaveAs() ' Based on macro shown in Greg Maxey's page at ' http://gregmaxey.mvps.org/File_Name_And_Path.htm ' ' Displays filename and path in document's title bar when saved using Save As ' Also updates filename fields in document ' Dialogs(wdDialogFileSaveAs).Show System.Cursor = wdCursorNormal ActiveWindow.Caption = ActiveDocument.FullName Dim oStory As Range Dim oField As Field For Each oStory In ActiveDocument.StoryRanges ' oStory.Fields.Update ' replace this with the following For-Next loop For Each oField In oStory.Fields If oField.Type = wdFieldFileName Then oField.Update End If Next oField If oStory.StoryType wdMainTextStory Then While Not (oStory.NextStoryRange Is Nothing) Set oStory = oStory.NextStoryRange oStory.Fields.Update Wend End If Next oStory Set oField = Nothing Set oStory = Nothing ActiveDocument.Save ' Saves document with updated field(s) End Sub In my limited testing, it seems to work. I also added the final save command. Of course, in a document with lots of fields my changes are going to make the macro take a more time, I expect. -- Charles Kenyon Word New User FAQ & Web Directory: http://addbalance.com/word Intermediate User's Guide to Microsoft Word (supplemented version of Microsoft's Legal Users' Guide) http://addbalance.com/usersguide See also the MVP FAQ: http://www.mvps.org/word which is awesome! --------- --------- --------- --------- --------- --------- This message is posted to a newsgroup. Please post replies and questions to the newsgroup so that others can learn from my ignorance and your wisdom. "Greg Maxey" wrote in message ... Milton See: http://gregmaxey.mvps.org/File_Name_And_Path.htm -- Greg Maxey/Word MVP A Peer in Peer to Peer Support Milton Ross wrote: The filename has been inserted into a document. I want the filename to update automatically when saved as another name. Is this possible? |
#6
|
|||
|
|||
Charles,
Good points. Next time I get around to working on the web page I will make these changes. Thanks. |
#7
|
|||
|
|||
While this works, it also messes up automatic backup because the second save
zaps the original backup, replacing it with the document just before the fields are updated but with any other changes. I have, on rare occasions, had my rep saved by these automatic backups and am loathe to disable that valuable feature. Given this, I've removed this macro from my own Add-In and gone with the change to normal.dot originally suggested in Greg's web page. -- Charles Kenyon Word New User FAQ & Web Directory: http://addbalance.com/word Intermediate User's Guide to Microsoft Word (supplemented version of Microsoft's Legal Users' Guide) http://addbalance.com/usersguide See also the MVP FAQ: http://www.mvps.org/word which is awesome! --------- --------- --------- --------- --------- --------- This message is posted to a newsgroup. Please post replies and questions to the newsgroup so that others can learn from my ignorance and your wisdom. "Charles Kenyon" wrote in message ... Because I don't like to mess with normal.dot and couldn't figure out how to do a global pseudo AutoOpen in a different global template, I added the following intercept to my global. It gives the filename and path on a document save. Sub FileSave() ' Based on macro shown in Greg Maxey's page at ' http://gregmaxey.mvps.org/File_Name_And_Path.htm ' ' Displays filename and path in document's title bar when saved using Save ' Also updates filename fields in document ' ActiveDocument.Save System.Cursor = wdCursorNormal ActiveWindow.Caption = ActiveDocument.FullName Dim oStory As Range Dim oField As Field For Each oStory In ActiveDocument.StoryRanges ' oStory.Fields.Update ' replace this with the following For-Next loop For Each oField In oStory.Fields If oField.Type = wdFieldFileName Then oField.Update End If Next oField If oStory.StoryType wdMainTextStory Then While Not (oStory.NextStoryRange Is Nothing) Set oStory = oStory.NextStoryRange oStory.Fields.Update Wend End If Next oStory Set oField = Nothing Set oStory = Nothing ActiveDocument.Save ' Saves document with updated field(s) End Sub -- Charles Kenyon Word New User FAQ & Web Directory: http://addbalance.com/word Intermediate User's Guide to Microsoft Word (supplemented version of Microsoft's Legal Users' Guide) http://addbalance.com/usersguide See also the MVP FAQ: http://www.mvps.org/word which is awesome! --------- --------- --------- --------- --------- --------- This message is posted to a newsgroup. Please post replies and questions to the newsgroup so that others can learn from my ignorance and your wisdom. "Charles Kenyon" wrote in message ... Greg, I made a couple of modifications to your macro because I sometimes use fields like Fill-In fields that I do _not_ want to update. My revision is below. Option Explicit Sub FileSaveAs() ' Based on macro shown in Greg Maxey's page at ' http://gregmaxey.mvps.org/File_Name_And_Path.htm ' ' Displays filename and path in document's title bar when saved using Save As ' Also updates filename fields in document ' Dialogs(wdDialogFileSaveAs).Show System.Cursor = wdCursorNormal ActiveWindow.Caption = ActiveDocument.FullName Dim oStory As Range Dim oField As Field For Each oStory In ActiveDocument.StoryRanges ' oStory.Fields.Update ' replace this with the following For-Next loop For Each oField In oStory.Fields If oField.Type = wdFieldFileName Then oField.Update End If Next oField If oStory.StoryType wdMainTextStory Then While Not (oStory.NextStoryRange Is Nothing) Set oStory = oStory.NextStoryRange oStory.Fields.Update Wend End If Next oStory Set oField = Nothing Set oStory = Nothing ActiveDocument.Save ' Saves document with updated field(s) End Sub In my limited testing, it seems to work. I also added the final save command. Of course, in a document with lots of fields my changes are going to make the macro take a more time, I expect. -- Charles Kenyon Word New User FAQ & Web Directory: http://addbalance.com/word Intermediate User's Guide to Microsoft Word (supplemented version of Microsoft's Legal Users' Guide) http://addbalance.com/usersguide See also the MVP FAQ: http://www.mvps.org/word which is awesome! --------- --------- --------- --------- --------- --------- This message is posted to a newsgroup. Please post replies and questions to the newsgroup so that others can learn from my ignorance and your wisdom. "Greg Maxey" wrote in message ... Milton See: http://gregmaxey.mvps.org/File_Name_And_Path.htm -- Greg Maxey/Word MVP A Peer in Peer to Peer Support Milton Ross wrote: The filename has been inserted into a document. I want the filename to update automatically when saved as another name. Is this possible? |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Automatically update TOC on Print &/or Save | Microsoft Word Help | |||
Inserting a file automatically | Microsoft Word Help | |||
Automatically update style | Microsoft Word Help | |||
How do you REALLY turn off automatically update styles in Word 200 | Microsoft Word Help | |||
preserving formatting of file that's been inserted into an open do | Page Layout |