View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
Jim Cone Jim Cone is offline
external usenet poster
 
Posts: 3,290
Default Word crashed after repeated XL macro use

Nice catch.
Jim Cone
San Francisco, USA

"Jezebel"

wrote in message
...
Not sure that this is entirely the cause of the problem, but your object
declaration and instantation are screwy. You're using early binding for the
declaration itself, but using late binding for the instantiation; and using
'as new' in the declaration is a recipe for disaster. (Some coding shops
have an absolute ban on the use of 'as new'.) As it is, this statement

Set appWD = CreateObject("Word.Application")

will instantiate TWO copies of Word: one created automatically for the first
use of appWD, and one from the CreateObject statement.

Try ---

Dim appWD as Word.Application

on error resume next
set appWD = Word.Application 'Get existing instance if any
on error goto ErrorHandler

if appWD is nothing then 'No existing instance,
so create a new one
set appWD = new Word.Application
end if

Two other issues that might be relevant --
1) Word may refuse to close if there were unhandled errors in the course of
your code.
2) There may be other code, from normal.dot or an add-in, that is
interfering.
After you've run your macro, check the Task Manager to see if there are any
remaining instances of Word.