Are you using Option Explicit? You have undeclared variables.
I would take the createobject out of the Dir loop. You are creating it each time. BAD IDEA!!! Create ONE instance of Word, and use it. Multiple creations is just asking for trouble. ONE instance of Word is quite capable of handling multiple document files.
So do Set appWord ONCE, but Set doc multiple times.
Set appWord = GetObject(, "Word.Application")
Do While strFile <> ""
strDocName = strdir + strfile
set doc = appWord.Document.Open(strDocName)
yadda yadda yadda
doc.Close
set doc = Nothing
Loop
Each INDIVIDUAL doc is opened, actioned, closed, and the doc object set to nothing...then a new DOC OBJECT created...but only ONE Word application object (instance) is used.
|