Could someone please let me know if the following simple VBScript is correct? It is supposed to close Excel after other processes have run (and left Excel open), but it doesn't work.
Set MyApp = CreateObject("Excel.Application")
MyApp.Quit
Could someone please let me know if the following simple VBScript is correct? It is supposed to close Excel after other processes have run (and left Excel open), but it doesn't work.
Set MyApp = CreateObject("Excel.Application")
MyApp.Quit
Try this please.
CreateObject creates a COM object, so your
starts a new Excel process. Use GetObject to "retrieve an existing object with the specified ProgID". See this for theory and praxis.
CreateObject
creates a new object. If I understand your question correctly you want to attach to already running (orphaned) Excel processes to terminate them. You can do that withGetObject
:Note that this will try to close all running Excel instances, discarding all changes in open workbooks. If you want it to save changes in open workbooks change the argument of the
Close
method toTrue
. If you have Excel instances you want to keep running, you need to add code to exclude them from being closed.Note also, that this will not forcibly terminate unresponsive instances. You'd need to kill the process for that: