View Single Post
  #6   Report Post  
Posted to microsoft.public.word.docmanagement
deb deb is offline
external usenet poster
 
Posts: 111
Default Automatic Filename Update

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!

"Deb" wrote:

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!

"Graham Mayor" wrote:

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



Deb wrote:
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!

"Jay Freedman" wrote:

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 FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

On Tue, 24 Mar 2009 16:52:01 -0700, Deb
wrote:

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!