


In Excel, to write and run a macro containing ODBC calls you execute the following steps. Specific versions of Excel may vary slightly.
1. Load the XLODBC.XLA add-in into Excel.
Make the add-in XLODBC.XLA available to the Excel spreadsheet. To do this, select "Add-Ins..." from the Tool menu, then check the box for "ODBC Add-In." Use the browse function, if necessary, to locate the add-in. If you cannot find it, reinstall Excel, being sure to select ODBC functionality.
2. Type the source code for your macro.
To do this, select "Macro...Module" from the Insert menu, and type your Excel/Visual Basic code. Be sure to enter the macro name in the sub statement. For example:
Sub Macro_Name()
End Sub
There are several ODBC functions
provided with the XLODBC.XLA add-in. A
complete list of them is included in "Excel/Visual Basic
Programmer's Guide."
Additional information is available in the "Excel Developer's
Kit" and the "MS Office
Developer's Kit," also from Microsoft Press.
Save the macro using the File menu "Save As" command. See the next step for suggested macro names.
3. Execute the Macro.
There are several ways to invoke macros from Excel. The most common is to select "Start" from the Run menu, or push <F5>. But easier still for the end user is to invoke the macros automatically using some standard macro names that are activated by Excel under certain circumstances.
Here is a list of these macros:
AutoExec Runs when Excel is activated AutoNew Runs when a new spreadsheet is created AutoOpen Runs when a spreadsheet is opened AutoClose Runs when a spreadsheet is closed AutoExit Runs when Excel is closedExcel/Visual Basic Sample
A sample macro written in Excel/Visual Basic is included on your AcuODBC installation disks. It is designed to retrieve a table from Vision and insert it in a new Excel spreadsheet.
This macro assumes that you created a DSN named "Customer" when running the sample program in Chapter 4. If you did not run the sample, create this DSN now, as described in Section 4.4 The Sample Data Source Name.
To run the macro, do the following:
1. Start Excel.
2. Select "Open" from the File menu and open the file labeled "xldemo.xls". It is located in the \acuodbc\macros directory of your hard drive.
3. Follow the directions on the screen.