View Single Post
 
Old 01-21-2013, 04:13 PM
fumei fumei is offline Windows 7 64bit Office XP
Expert
 
Join Date: Jan 2013
Posts: 440
fumei is on a distinguished road
Default

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.
Reply With Quote