Visual Basic for Applications Reference

CreateObject Function Example

This example uses the CreateObject function to set a reference (xlApp) to Microsoft Excel. It uses the reference to access the Visible property of Microsoft Excel, and then uses the Microsoft Excel Quit method to close it. Finally, the reference itself is released.

  Dim xlApp As Object   ' Declare variable to hold the reference.
   
Set xlApp = CreateObject("excel.application")
   ' You may have to set Visible property to True
   ' if you want to see the application.
xlApp.Visible = True
   ' Use xlApp to access Microsoft Excel's 
   ' other objects.
xlApp.Quit   ' When you finish, use the Quit method to close 
Set xlApp = Nothing   ' the application, then release the reference.