Thread: [Solved] Auto update Filename field
View Single Post
 
Old 10-18-2012, 03:19 AM
Oliver Beirne Oliver Beirne is offline Windows XP Office 2007
Novice
 
Join Date: Jan 2012
Posts: 7
Oliver Beirne is on a distinguished road
Default Auto update Filename field

Hi

I have some VBA that opens all Word documents in a given folder, pastes their content into a blank template then saves with the original filename in a new folder.

As part of this I want the filename field in the header of the new documents to automatically update with the document filename. I nknwo you can use F9 but I don't want this to be a task for the document users.

I've seen some vba examples such as:
Code:
 
Dim aStory As Range 
Dim aField As Field 
 
' Automatically update all fields in document when it is opened
For Each aStory In ActiveDocument.StoryRanges 
  For Each aField In aStory.Fields 
    aField.Update 
  Next aField 
Next aStory
but these all appear in their own sub routines and when I try to add it to my exisiting code it doesn't work.

I'd really appreciate any pointers on how to solve this, thanks.

Last edited by macropod; 10-18-2012 at 02:33 PM. Reason: Added code tags & formatting
Reply With Quote