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.
To close Microsoft Access from Microsoft Excel, follow these steps:
- Start Microsoft Access and open any database.
- Start Microsoft Excel, point to Macro on the Tools menu, and then click Visual Basic Editor.
- On the Insert menu, click Module.
- Type the following Sub procedure:
Sub OleAccess()
Dim appAccess as Object
Set appAccess = GetObject(, "Access.Application")
appAccess.Quit acSave
End Sub
- To run this code, click Run Sub/UserForm on the Run menu, or call the Sub procedure from another procedure.
When it runs, the GetObject() function sets the appAccess variable to the first available open instance of Microsoft Access. At the end, it closes Microsoft Access with appAccess.Quit.
NOTE: If you do not have Microsoft Access running in the background when you run the procedure, you receive a run-time error. You can trap
for this error by using
On Error.