Quit word from excel with VBA?

Just looking for a solution to quiting word with VBA. Im running a macro from excel, which opens word, mail merges some data then quits word. To quit word i have defined it as an object (objword) then do:

objword.application.quit wddonotsavechanges

This works; however everytime it tries to close i always get the following message:

this task is taking longer than expected. Do you want to continue waiting?

As soon as i click no on that it quits word and the everything is fine. Is there any reason for this been so slow/anyway around this to just quit the application cleany?

✅ Answers

  • Answerer 1

    Run the macro with the word application object visible to see if there is a dialog that’s being spawned?

    I assume you’re doing something like:

    Dim objWord as Object
    Set objWord = CreateObject(“Word.Application”)

    in which case I’d assume you haven’t added a reference to the Microsoft Word Object Library to your references…which would mean that the constant ‘wddonotsavechanges’ would have no context and would resolve to zero (which is what it would resolve to normally). I only mention that since there might be other instances where you’re using constants that may be causing unintended consequences.

  • Leave a Comment