Show Contents / Index / Search

Automate Applications from Reflection 2008

You can use Reflection 2008 to control an application that supports Automation (such as Word or Excel).

  1. 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.
  2. 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

  3. 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")

  4. 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.Workbooks.Add
    excelApp.ActiveSheet.Range("B2").Select
    excelApp.ActiveCell.Value = 14

Automation Example