Changing Locked property of Fields in Doc without using Documents.

M

mansky99

Hi,
I have a User who, by mistake, used a Date Field in Word documents to place
a date in a document. The intention was to have that date to be fixed and
unchanged
the next time the document was opened. The dates are journal entries (ie. a
date and some text)
and hence it's important that the dates remain unchanged upon subsequent use
of the file.

I have a script to go thru all the Word docs on the machine where the
problem resides.
However, it appears that I have to first use the method Documents.Open
before I can use the method Documents.Fields.Count to see if there are any
fields in a given document.

Here's a code snippet of the script to toggle the Locked property of all
fields in a given document
from False to True :
For i = 1 To NF
Fullname = Pathnames(i) & Filenames(i)
Documents.Open Filename:=Fullname
If (Documents(Fullname).Fields.Count > 0) Then
For Each ADF In Documents(Fullname).Fields
If (ADF.Locked = False) Then
ADF.Locked = True
Documents.Close SaveChanges:=wdSaveChanges
Else
Documents.Close SaveChanges:=wdDoNotSaveChanges
End If
Next ADF
End If
Loop i

where the Variant arrays Pathnames and Filenames contain the paths and
filenames of all the
Word documents on the affected machine.

The problem is that as soon as Documents.Open is called, the date fields (as
per design) are updated, thereby nullifying my script.

I'd like to change the Locked property value of any fields in a given
document from False to True
(to thereby prevent subsequent updating of date fields), but I can't seem to
get around using
Documents.Open. If I leave out the call to Documents.Open, I get a 'Bad
filename' error from the
Documents(Fullname).Fields.Count statement.

Any ideas on how to toggle the Locked property, or other ideas would be
greatly appreciated!

Ed
 
P

Peter Jamieson

Although I can't see a way to open the document via Word without Word
updating the date fields, on the Windows version I think it would be
possibel to inspect the value of
ActiveDocument.BuiltInDocumentProperties(wdPropertyTimeLastSaved), extract
the date from that, and stuff it programmatically into the document.

Or maybe something along those lines...

Peter Jamieson
 
D

Daiya Mitchell

One alternate solution might be to remove the Date field in the document,
and change it to a CreateDate field, which will reflect the date of
creation. You could do this retroactively. Unfortunately, as far as I know,
CreateDate is per document, not creation of field, so multiple dates in the
same doc would be the same.

Are you on a Mac? This is a Mac newsgroup. If so, what version of Word and
OS are you dealing with?

For Word on Windows questions, start here:
http://www.microsoft.com/office/community/en-us/FlyoutOverview.mspx#13
Or here:
http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=
 
M

mansky99

Yes, I'm running Office/Word 10.1.6 on Mac OSX 10.2.8.

Would changing the Field require using Documents.Open first?
 
M

mansky99

Thanks Peter, that's a good idea. I suspect that indeed I'll have to use the
method Documents.Open to interrogate a given document to know if it even
has fields, and then parse thru the fields in a given document to toggle the
Locked
property to True if it's False. Looks like for the case of a document with
multiple Date
Fields in a document, I'll lose the original dates in those fields once I
open the document.

Thanks for the help!

Ed
 
P

Peter Jamieson

The only "improvement" I can think of for that is
a. open the document
b. get the date you need to preserve
c. save as RTF
d. open the RTF as a text file
e. modify all the date fields directly in the RTF
f. reload the RTF as a Word document
g. save as .doc

Haven't tried it, don't know how feasible on Mac, steps (c) & (f)
potentially damage the document, but you wouldn't have to alter the system
date.

Peter Jamieson
 

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