Hello
I created a Word document template from a document created at another
institution, and stupidly didn't notice that before there were hundreds of
documents in my organization's file system with the other company's name in
the "Company" BuiltInDocumentProperties.
I wrote the routine below to traverse the file tree and update each file. I
change the system time to the original modified time for each file so I don't
end up setting every file to be modified now.
HOWEVER, (A) this is insanely slow (even if I turn off
Application.ScreenUpdating; and (B) I noticed that from Windows Explorer, you
can modify these properties without opening the file.
Does anyone know either:
1) How I could improve the performance in general; or
2) Achieve the same result without having Word open each document?
Tx & rgds
Bongo
Sub Traverse(folderspec)
Dim fs, f, fl, fc, s, company
Dim realdate, realtime, filetime
realdate = Date
realtime = Time()
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folderspec)
Set fc = f.Files
For Each fl In fc
If fl.Type = "Microsoft Word Document" Then
filetime = fl.DateLastModified
Documents.Open FileName:=fl.Path
company = Documents(fl.Name).BuiltInDocumentProperties("Company")
If company = "OTHER COMPANY" Then
Time = filetime
Date = filetime
Documents(fl.Name).BuiltInDocumentProperties("Company") =
"MY COMPANY"
Documents(fl.Name).BuiltInDocumentProperties("Keywords") = ""
Documents(fl.Name).Save
End If
Documents(fl.Name).Close
End If
Next
' RECURSIVE PART, DISABLED FOR TESTING
' Set fc = f.subfolders
' For Each fl In fc
' Traverse (fl.Path)
' Next
Time = realtime
End Sub
Jezebel - 10 Feb 2006 07:08 GMT
There's a freebie application somewhere on the Microsoft site, that reads
and writes Office document properties. I've no idea whether it's faster. But
with only a few hundred documents to do, why worry about it. Leave it
running over night -- even at an insanely slow pace, they'll be done by
morning. And presumably you need to do it only once.
> Hello
>
[quoted text clipped - 58 lines]
> Time = realtime
> End Sub
Bongo - 12 Feb 2006 12:10 GMT
Thanks Jezebel
I don't know if this is what you are referring to, but in fact there is an
API for modifying document properties without opening the files in the office
application. It is contained in "Dsofile.dll" and is available here:
http://support.microsoft.com/?id=224351. The performance is substantially
better than opening the file.
If anyone wants sample code, let me know.
Rgds
Bongo
> There's a freebie application somewhere on the Microsoft site, that reads
> and writes Office document properties. I've no idea whether it's faster. But
[quoted text clipped - 64 lines]
> > Time = realtime
> > End Sub
Doug Robbins - Word MVP - 12 Feb 2006 15:25 GMT
The use of the DSOFile.dll is discussed in the article "Getting access to
the Document Properties of a Word file" at:
http://www.word.mvps.org/FAQs/MacrosVBA/DSOFile.htm

Signature
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
> Thanks Jezebel
>
[quoted text clipped - 85 lines]
>> > Time = realtime
>> > End Sub