Quitting Applications

Because OLE Automation objects can use a significant amount of memory, you should explicitly close an object when you no longer need it. Many OLE Automation objects support a Quit method that closes an object and quits the OLE server application from inside the OLE controller application. The following code explicitly closes Microsoft Project.


proj.Application.Quit

Setting an object variable to "nothing" both releases the object variable and closes the OLE server application. The following code opens a document in Word and then sets the variable to "nothing," thereby closing the OLE server application.


Dim wdBasic As Object

Set wdBasic = CreateObject("word.basic")
wdBasic.FileOpen "C:\msoffice\winword\Speedup.doc"
Set wdBasic = Nothing