VBA Express Forum  




Go Back   VBA Express Forum > VBA Code & Other Help > Word Help
     Feedback     
Register FAQ Members Arcade Knowledge Base Training Articles Consulting

Reply
 
Thread Tools Display Modes
Old 01-14-2010, 12:42 AM   #1
bstephens

 
Joined: Nov 2009
Posts: 86
Kb Entries: 0
Articles: 0
word 2007 - automatically update fields in footer after save event

Does anybody know the best practice to automatically update the fields (specifically filename and path field) in a footer after the user clicks save. I thought I had this figured out awhile ago, but apparently I do not.

I have really struggled trying to find something that works and I'm not sure why I can't come up with a solution to what seems like a pretty basic problem.

Thanks in advance for any ideas.

Brian

Local Time: 11:49 AM
Local Date: 05-22-2013
Location:

 
Reply With Quote Top
Old 01-14-2010, 10:07 AM   #2
fumei

 
Joined: May 2004
Posts: 6,300
Kb Entries: 8
Articles: 0
You could add update coding to the Save event itself. This means writing a FileSave event that includes both the field updating and the saving itself.

Local Time: 06:49 PM
Local Date: 05-22-2013
Location:

 
Reply With Quote Top
Old 01-14-2010, 10:13 AM   #3
Tinbendr
 
Tinbendr's Avatar

 
Joined: Jun 2005
Posts: 983
Kb Entries: 0
Articles: 0
VBA:
Private Sub FileSave() Dim rngStory As Range For Each rngStory In ActiveDocument.StoryRanges With rngStory .Fields.Update End With Next rngStory End Sub
VBA tags courtesy of www.thecodenet.com


+------+
| David |
+------+

Local Time: 12:49 PM
Local Date: 05-22-2013
Location:

 
Reply With Quote Top
Old 01-14-2010, 10:55 AM   #4
fumei

 
Joined: May 2004
Posts: 6,300
Kb Entries: 8
Articles: 0
Tinbendr, you forgot to do the file saving instruction!

That would do the update...but NOT do the actual saving of the file. The file would NOT be saved.

I am not a fan of going through all the StoryRanges, unless actually needed. Going through all the StoryRanges means looping through (assuming there are no Comments, or Endnotes):

MainTextStory
EvenPagesHeaderStory
PrimaryHeaderStory
EvenPagesFooterStory
PrimaryFooterStory
FirstPageheaderStory
FirstPageFooterStory

in that order. Since (again assuming you do NOT want to check through the Comments story, the EndNotes Story, the FootNotesStory or the TextFrameStory....then why not just action the stories you weant to explicitly?
VBA:
Sub FileSave() Dim oHF As HeaderFooter Dim oSection As Section Dim rngStory As Range For Each oSection In ActiveDocument.Sections For Each oHF In oSection.Headers oHF.Range.Fields.Update Next For Each oHF In oSection.Footers oHF.Range.Fields.Update Next Next With ActiveDocument.Range .Fields.Update End With ActiveDocument.Save End Sub
VBA tags courtesy of www.thecodenet.com

Local Time: 06:49 PM
Local Date: 05-22-2013
Location:

 
Reply With Quote Top
Old 01-14-2010, 11:38 AM   #5
Tinbendr
 
Tinbendr's Avatar

 
Joined: Jun 2005
Posts: 983
Kb Entries: 0
Articles: 0
Quote:
 
Originally Posted by: fumei
Tinbendr, you forgot to do the file saving instruction!

DOH!


+------+
| David |
+------+

Local Time: 12:49 PM
Local Date: 05-22-2013
Location:

 
Reply With Quote Top
Old 01-14-2010, 03:43 PM   #6
macropod
 
macropod's Avatar

 
Joined: Jul 2008
Posts: 1,931
Kb Entries: 0
Articles: 7
Of course, if you update the fields after saving, the state reverts to unsaved. And if one of those fields is a SAVEDATE field, you'll be chasing your tail forever ...


Cheers
Paul Edstein
[MS MVP - Word]

Local Time: 04:49 AM
Local Date: 05-23-2013
Location:

 
Reply With Quote Top
Old 01-15-2010, 10:31 AM   #7
fumei

 
Joined: May 2004
Posts: 6,300
Kb Entries: 8
Articles: 0
That macropod, always finding the best part.

Although, that is why I did the update BEFORE the save. Because, then who cares? Except....for that darn SAVEDATE.

Good one.

Local Time: 06:49 PM
Local Date: 05-22-2013
Location:

 
Reply With Quote Top
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -7. The time now is 11:49 AM.


Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright © 2004 - 2012 VBA Express