Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: Applications Run from Automation Do Not Always Close


View products that this article applies to.

Summary

When you open other applications, such as other Microsoft Office 2000 programs, through Automation code, the applications that you open may not always close when your code finishes running.

↑ Back to the top


More information

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. You can use Automation code to open and manipulate other Microsoft Office programs. When you open a program by using Automation, an instance of the program is created in memory. If you don't close each instance of a program that you open, that instance may remain open but hidden. Each time that this happens, additional memory resources are consumed on you computer until you either restart the computer or shut down the hidden instances of the program manually. Having multiple, hidden instances of a program in memory can adversely affect the performance of your computer.

To prevent multiple, hidden instances of a program started with Automation code from getting stuck in memory, explicitly close each instance of the program when you finish working with it. You can explicitly close an instance of an Office 2000 program by using the Quit method at the end of your Automation code. The following Office 2000 applications support the Quit method:
  • Microsoft Access
  • Microsoft Excel
  • Microsoft Front Page
  • Microsoft Graph
  • Microsoft Power Point
  • Microsoft Outlook
  • Microsoft Word
The following example starts an instance of Excel and opens a workbook. It then uses the Quit method to terminate the instance of Excel when the procedure is finished running.
Function Automation_To_Excel()
    Dim objExcel As Object
    
    ' Create a new instance of Excel.
    Set objExcel = CreateObject("Excel.Application")
    
    ' Show the instance of Excel on the screen.
    objExcel.Visible = True
    
    ' Open a file named SampleFile.xls
    objExcel.Workbooks.Open ("C:\My Documents\SampleFile.xls")
    
    ' Explicitly close the instance of Excel to free up memory
    ' and set the variable to Nothing to free up the name
    ' space in Access.
    objExcel.Quit
    Set objExcel = Nothing
End Function
				

Converting from Microsoft Access 2.0

In Access 2.0, the Quit method needed to be enclosed in brackets to work.
objExcel.[Quit]
				
When you convert a database that uses the Quit method in this fashion from Access 2.0 to Access 2000, you will need to manually remove the brackets from the Quit method. The brackets will not cause an error, but if they are present, the Quit method will not close the instance of the program being run.

Steps to Manually Shut Down Hidden Instances of Programs

Windows 95 and Later

  1. Press CTRL+ALT+DELETE to open the Close Programs dialog box.
  2. Click to select the instance of the program that you want to shut down, and then click End Task.

Windows NT

  1. Press CTRL+ALT+DELETE to open the Windows NT Security dialog box.
  2. Click Task Manager.
  3. Switch to the Processes tab.
  4. Click to select the process that you want to shut down, and then click End Process.

Steps to Reproduce the Problem

WARNING: Running this sample code will leave hidden instances of Excel running in your computer's memory. You will have to follow the steps listed under the "How to Manually Shut Down Hidden Instances of Programs" section earlier in this article to close these instances. Leaving hidden programs running in your computer's memory could affect your computer's performance.

The following code opens an instance of Excel and a sample file, but fails to explicitly close the instance. When the function is finished, the instance of Excel is still in memory.
  1. Type or paste the following code into a module.
    Function Automation_To_Excel()
        Dim objExcel As Object
        
        ' Create a new instance of Excel.
        Set objExcel = CreateObject("Excel.Application")
        
        ' This sample will actually leave a hidden copy of Excel
        ' in your computer's memory. To leave an open copy of Excel
        ' on the task bar, remove the comment mark from the
        ' line below.
        ' objExcel.Visible = True
        
        ' Open a file named SampleFile.xls
        objExcel.Workbooks.Open ("C:\My Documents\SampleFile.xls")
    End Function
    					
  2. In the Immediate Window, type the following line, and then press ENTER:
    ?Automation_To_Excel
  3. Use one of the methods listed earlier in this article to find and remove the hidden instance of Excel.

↑ Back to the top


References

For more information about programming with Automation, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type Understanding Automation in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

↑ Back to the top


Article Info
Article ID : 210129
Revision : 4
Created on : 1/1/0001
Published on : 1/1/0001
Exists online : False
Views : 265