Automatic Filename Update

D

Deb

A few years ago, I created a protected form which has a footer containing a
filename field that would update as a user copied and renamed the file.
Recently, the filename has not been updating. F9 works, but you have to
unprotect and resave the document, and when tested, also does not change the
filename when renamed to a new file. Also found a macro which works as F9
does. To do these steps would be like re-inventing the wheel. The purpose
of this form was to make it user-proof and setup up general forms for each
client we have - all a user needed to do was fill in specific info, such as
account amounts, and the form would update the filename and retain the basic
client info. Did Microsoft change something? And how can I get my nice
little feature back? Any help will be greatly appreciated. Thanks!
 
J

Jay Freedman

That behavior changed in Word 2002, as described in
http://support.microsoft.com/?kbid=832897.

I sympathize -- especially as the stated reason for the change is unbelievably
bogus -- but using a series of macros is the only way to avoid needing manual
updating. Besides the AutoOpen macro shown in the KB article, you would also
need one that intercepts the Save As command and saves, updates the field, and
saves again (the first save changes the name of the file, but updating the field
"dirties" the document and makes another save necessary).

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.
 
D

Deb

Well....grrrrrrrr.... Thank you for responding so quickly. Macros are not
working within the documents - the option is greyed out due I suppose to the
forms being protected. I found another macro that will change text in
batches, and since the filename changes would for the most part be the fiscal
year, do you think that would work? Would a macro for changing text in
batches of files work if the files are protected forms? I really, truly,
absolutely, do not want to have to update each and every file individually.
And whatever happened to the adage, 'if it ain't broke, don't fix it'???
Hope you're having a great day!
 
G

Graham Mayor

If you put the filename field in the body of the document rather than the
footer and check the calculate on exit check box of one of the fields that
you will tab out of, the field will be updated.
or
You could add an update macro to the toolbar

Sub UnpdateFieldInFooter()
Dim oField As Field
Dim oSection As Section
Dim oFooter As HeaderFooter
For Each oSection In ActiveDocument.Sections
For Each oFooter In oSection.Footers
If oFooter.Exists Then
For Each oField In oFooter.Range.Fields
If oField.Type = wdFieldFileName Then
oField.Update
End If
Next oField
End If
Next oFooter
Next oSection
End Sub

Batch macros will work on protected forms -
http://www.gmayor.com/batch_replace.htm provided the extra code to unlock
the forms where required is included. eg

Dim bProtected As Boolean
Dim sPassword As String
sPassword = ""
'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=sPassword
End If

'do your stuff

'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=sPassword
End If


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
D

Deb

Thanks, Graham. It's funny - got the batch code from your site yesterday,
but not the additional protect/unprotect code. Cute kitties you have on
there. I will try each of the things offered in the posts from you and Jay.
Will add to this post with what actually worked best. Thanks again!
 
D

Deb

Putting the filename in the body of the document would have required each
file to be edited, or recreated, individually. BUT THE SECOND OPTION, adding
the macro to the toolbar - WORKS PERFECTLY EVEN IN PROTECTED DOCUMENTS!
Created the macro, added it to the toolbar, and tested it. Opened different
protected files which had filename fieldcodes in footers, changed the other
data that I wanted to change, hit the macro button on the toolbar, instant
filename change in the protected documents' footers. Beautiful! Thank you
ever so much!
 
G

Graham Mayor

A minor addition to the macro will ensure that it always shows the correct
filename

Sub UnpdateFieldInFooter()
Dim oField As Field
Dim oSection As Section
Dim oFooter As HeaderFooter
'****************
ActiveDocument.Save
'****************
For Each oSection In ActiveDocument.Sections
For Each oFooter In oSection.Footers
If oFooter.Exists Then
For Each oField In oFooter.Range.Fields
If oField.Type = wdFieldFileName Then
oField.Update
End If
Next oField
End If
Next oFooter
Next oSection
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
D

dp

Using Word 2007, windows XP. I copied this macro and started to install. I
copied it fine but got mixed up with the Modules and projects described in
your "Installing Macros From Listings" so closed the window. Tested anyway
and it seems to work - what problems am I causing by not getting it in the
right project / module. Beginning to think I'\'m better off manually
updating the field.
 
G

Graham Mayor

Don't worry too much about the modules. If it works, it is probably fine
where it is.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
D

dp

Thank you

Graham Mayor said:
Don't worry too much about the modules. If it works, it is probably fine
where it is.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - 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