Automate Applications from Reflection 2008
You can use Reflection 2008 to control an application that supports Automation (such as Word or Excel).
- In the Visual Basic Editor, add a reference to the object library for the application you want to control: Choose Tools > References, select an application from the Available References list, then click OK.
- In the procedure code, use Dim to declare an object variable for the object you want to control. For example, this statement declares an Excel object:
Dim excelApp As Excel.Application
- Use Set to assign an object to the object variable. Use either CreateObject or GetObject to get the object. For example, this statement creates a new instance of Excel:
Set excelApp = CreateObject("Excel.Application")
- Use the object to manipulate the application by using commands supported by that application. For example, these statements use Excel objects, methods, and properties to make Excel visible, create a new Excel workbook, and put the number 14 in cell B2:
excelApp.Visible = True
excelApp.ActiveCell.Value = 14