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

Thanks for the response, Jim, and sorry for the confusion. The objects are
declared with:
Dim appWD As New Word.Application
Dim doc As Word.Document
and set with:
Set appWD = CreateObject("Word.Application")
appWD.Visible = False
Set doc = appWD.Documents.Add

My assumption was that Excel VBA would thereafter recognize "doc" as having
Word properties and methods, so
doc.Close SaveChanges:=wdDoNotSaveChanges
should be recognized. Is this an inaccurate assumption?

Ed

"Jim Cone" wrote in message
...
Ed,

There are a couple of things that could be confusing to the
applications...

How would Word or Excel read: appWD.doc.Close...?
Is appWD the document or is doc the document?
Maybe doc is not the best choice for a Word object variable.

Since wdDoNotSaveChanges is not an Excel constant and you are
running the program from Excel, you should qualify the constant...
appWD.wdDoNotSaveChanges
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"Ed" wrote in message
...
I have an Excel macro that call a new instance of Word and creates a new
document, does some things in the doc, then closes the doc without saving
changes and sets the doc and Word app objects to nothing using
doc.Close SaveChanges:=wdDoNotSaveChanges
appWD.Quit
Set doc = Nothing
Set appWD = Nothing

I used the macro this morning repeatedly - perhaps 30 times in succession.
(Each time had to be an individual call - there was no way to loop this.)
After doing all that, I did not check to see if there were any open
instances of Word left (there were none during testing, so I didn't think
I
should have to) or other issues. Then I tried to open a Word document
with
an AutoOpen macro, and Word crashed. Subsequent attempts produced further
crashes. I wound up eventually having to rebuild Normal to get things
moving again.

Question: Could just repeatedly accessing the Word app have caused this?
Is there a better way to avoid these issues in the future?

Ed