+ Reply to Thread
Results 1 to 10 of 10

Thread: Word crashed after repeated XL macro use

  1. #1
    Ed
    Guest

    Word crashed after repeated XL macro use

    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



  2. #2
    Jim Cone
    Guest

    Re: Word crashed after repeated XL macro use

    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" <ed_millis@NO_SPAM.yahoo.com> wrote in message news:OHMgzikjGHA.1940@TK2MSFTNGP02.phx.gbl...
    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



  3. #3
    Ed
    Guest

    Re: 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" <jim.coneXXX@rcn.comXXX> wrote in message
    news:uErRdxljGHA.1264@TK2MSFTNGP05.phx.gbl...
    > 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" <ed_millis@NO_SPAM.yahoo.com> wrote in message
    > news:OHMgzikjGHA.1940@TK2MSFTNGP02.phx.gbl...
    > 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
    >
    >




  4. #4
    Jim Cone
    Guest

    Re: Word crashed after repeated XL macro use

    Ed,

    re: "so doc.Close SaveChanges:=wdDoNotSaveChanges
    should be recognized. Is this an inaccurate assumption?"

    Yes, however you may have lucked out.
    Since the constant's value in Word is 0 (zero), that may the
    value being assigned when Excel can't read it.
    However, Excel should be throwing an error.
    Unless... there is an "on error resume next" someplace.
    --
    Jim Cone
    San Francisco, USA
    http://www.officeletter.com/blink/specialsort.html


    "Ed" <ed_millis@NO_SPAM.yahoo.com> wrote in message news:eswcHpmjGHA.456@TK2MSFTNGP05.phx.gbl...
    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" <jim.coneXXX@rcn.comXXX> wrote in message
    news:uErRdxljGHA.1264@TK2MSFTNGP05.phx.gbl...
    > 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" <ed_millis@NO_SPAM.yahoo.com> wrote in message
    > news:OHMgzikjGHA.1940@TK2MSFTNGP02.phx.gbl...
    > 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
    >
    >




  5. #5
    Ed
    Guest

    Re: Word crashed after repeated XL macro use

    > Unless... there is an "on error resume next" someplace.
    Wow, Jim! You are _good_!! As a matter of fact, the whole end of the macro
    is
    CleanUp:
    On Error Resume Next
    doc.Close SaveChanges:=wdDoNotSaveChanges
    appWD.Quit
    Set doc = Nothing
    Set appWD = Nothing
    On Error GoTo 0
    End Sub

    The intention was that if an error is thrown early into the macro, like
    after setting the Word app object but not the document object, I could drop
    here to close out any object still remaining without causing more errors
    because I'm trying to manipulate an object that doesn't exist.

    Perhaps better would be to explicitly label the doc variable as belonging to
    the Word application when I close?
    CleanUp:
    On Error Resume Next
    appWD.doc.Close SaveChanges:=wdDoNotSaveChanges
    appWD.Quit
    Set doc = Nothing
    Set appWD = Nothing
    On Error GoTo 0
    End Sub


    "Jim Cone" <jim.coneXXX@rcn.comXXX> wrote in message
    news:e19QoBnjGHA.4276@TK2MSFTNGP03.phx.gbl...
    > Ed,
    >
    > re: "so doc.Close SaveChanges:=wdDoNotSaveChanges
    > should be recognized. Is this an inaccurate assumption?"
    >
    > Yes, however you may have lucked out.
    > Since the constant's value in Word is 0 (zero), that may the
    > value being assigned when Excel can't read it.
    > However, Excel should be throwing an error.
    > Unless... there is an "on error resume next" someplace.
    > --
    > Jim Cone
    > San Francisco, USA
    > http://www.officeletter.com/blink/specialsort.html
    >
    >
    > "Ed" <ed_millis@NO_SPAM.yahoo.com> wrote in message
    > news:eswcHpmjGHA.456@TK2MSFTNGP05.phx.gbl...
    > 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" <jim.coneXXX@rcn.comXXX> wrote in message
    > news:uErRdxljGHA.1264@TK2MSFTNGP05.phx.gbl...
    >> 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" <ed_millis@NO_SPAM.yahoo.com> wrote in message
    >> news:OHMgzikjGHA.1940@TK2MSFTNGP02.phx.gbl...
    >> 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
    >>
    >>

    >
    >




  6. #6
    Jim Cone
    Guest

    Re: Word crashed after repeated XL macro use

    Ed,
    re: "appWD.doc.Close SaveChanges:=wdDoNotSaveChanges"

    No, don't do that, you are right back to problem I pointed out
    in my first message.
    The simplest way is to just use the constant's value...
    doc.Close SaveChanges:=0
    or the more self-explanatory way...
    doc.Close SaveChanges:=AppWD.wdDoNotSaveChanges

    Of course, all of this may not mean much if your app still crashes.
    Regards,
    Jim Cone


    "Ed" <ed_millis@NO_SPAM.yahoo.com> wrote in message news:uvTFgOnjGHA.836@TK2MSFTNGP02.phx.gbl...
    > Unless... there is an "on error resume next" someplace.

    Wow, Jim! You are _good_!! As a matter of fact, the whole end of the macro
    is
    CleanUp:
    On Error Resume Next
    doc.Close SaveChanges:=wdDoNotSaveChanges
    appWD.Quit
    Set doc = Nothing
    Set appWD = Nothing
    On Error GoTo 0
    End Sub

    The intention was that if an error is thrown early into the macro, like
    after setting the Word app object but not the document object, I could drop
    here to close out any object still remaining without causing more errors
    because I'm trying to manipulate an object that doesn't exist.

    Perhaps better would be to explicitly label the doc variable as belonging to
    the Word application when I close?
    CleanUp:
    On Error Resume Next
    appWD.doc.Close SaveChanges:=wdDoNotSaveChanges
    appWD.Quit
    Set doc = Nothing
    Set appWD = Nothing
    On Error GoTo 0
    End Sub


    "Jim Cone" <jim.coneXXX@rcn.comXXX> wrote in message
    news:e19QoBnjGHA.4276@TK2MSFTNGP03.phx.gbl...
    > Ed,
    >
    > re: "so doc.Close SaveChanges:=wdDoNotSaveChanges
    > should be recognized. Is this an inaccurate assumption?"
    >
    > Yes, however you may have lucked out.
    > Since the constant's value in Word is 0 (zero), that may the
    > value being assigned when Excel can't read it.
    > However, Excel should be throwing an error.
    > Unless... there is an "on error resume next" someplace.
    > --
    > Jim Cone
    > San Francisco, USA
    > http://www.officeletter.com/blink/specialsort.html
    >
    >
    > "Ed" <ed_millis@NO_SPAM.yahoo.com> wrote in message
    > news:eswcHpmjGHA.456@TK2MSFTNGP05.phx.gbl...
    > 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" <jim.coneXXX@rcn.comXXX> wrote in message
    > news:uErRdxljGHA.1264@TK2MSFTNGP05.phx.gbl...
    >> 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" <ed_millis@NO_SPAM.yahoo.com> wrote in message
    >> news:OHMgzikjGHA.1940@TK2MSFTNGP02.phx.gbl...
    >> 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
    >>
    >>

    >
    >




  7. #7
    Jezebel
    Guest

    Re: Word crashed after repeated XL macro use

    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.







    "Ed" <ed_millis@NO_SPAM.yahoo.com> wrote in message
    news:eswcHpmjGHA.456@TK2MSFTNGP05.phx.gbl...
    > 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" <jim.coneXXX@rcn.comXXX> wrote in message
    > news:uErRdxljGHA.1264@TK2MSFTNGP05.phx.gbl...
    >> 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" <ed_millis@NO_SPAM.yahoo.com> wrote in message
    >> news:OHMgzikjGHA.1940@TK2MSFTNGP02.phx.gbl...
    >> 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
    >>
    >>

    >
    >




  8. #8
    Jim Cone
    Guest

    Re: Word crashed after repeated XL macro use

    Nice catch.
    Jim Cone
    San Francisco, USA

    "Jezebel"
    <warcrimes@whitehouse.gov>
    wrote in message
    news:uan4BmnjGHA.4368@TK2MSFTNGP03.phx.gbl...
    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.


  9. #9
    Ed
    Guest

    Re: Word crashed after repeated XL macro use

    Wow! Thanks, Jezebel. I owe you big for that one! I guess I need to go
    back and brush up on some things - and see what other bad habits I've let
    get in here.

    Ed

    "Jezebel" <warcrimes@whitehouse.gov> wrote in message
    news:uan4BmnjGHA.4368@TK2MSFTNGP03.phx.gbl...
    > 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.
    >
    >
    >
    >
    >
    >
    >
    > "Ed" <ed_millis@NO_SPAM.yahoo.com> wrote in message
    > news:eswcHpmjGHA.456@TK2MSFTNGP05.phx.gbl...
    >> 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" <jim.coneXXX@rcn.comXXX> wrote in message
    >> news:uErRdxljGHA.1264@TK2MSFTNGP05.phx.gbl...
    >>> 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" <ed_millis@NO_SPAM.yahoo.com> wrote in message
    >>> news:OHMgzikjGHA.1940@TK2MSFTNGP02.phx.gbl...
    >>> 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
    >>>
    >>>

    >>
    >>

    >
    >




  10. #10
    Ed
    Guest

    Re: Word crashed after repeated XL macro use

    Jezebel and Jim:

    Just ran the Excel macro again, about 25 times through. No leftovers this
    time! Then I launched Word and macros run fine there. Thank you both for
    your help with this.

    Ed

    "Ed" <ed_millis@NO_SPAM.yahoo.com> wrote in message
    news:%23ePZC8ujGHA.4212@TK2MSFTNGP03.phx.gbl...
    > Wow! Thanks, Jezebel. I owe you big for that one! I guess I need to go
    > back and brush up on some things - and see what other bad habits I've let
    > get in here.
    >
    > Ed
    >
    > "Jezebel" <warcrimes@whitehouse.gov> wrote in message
    > news:uan4BmnjGHA.4368@TK2MSFTNGP03.phx.gbl...
    >> 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.
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >> "Ed" <ed_millis@NO_SPAM.yahoo.com> wrote in message
    >> news:eswcHpmjGHA.456@TK2MSFTNGP05.phx.gbl...
    >>> 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" <jim.coneXXX@rcn.comXXX> wrote in message
    >>> news:uErRdxljGHA.1264@TK2MSFTNGP05.phx.gbl...
    >>>> 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" <ed_millis@NO_SPAM.yahoo.com> wrote in message
    >>>> news:OHMgzikjGHA.1940@TK2MSFTNGP02.phx.gbl...
    >>>> 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
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0