B
Bongo
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
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