contents.gifindex.gifprev1.gifnext1.gif

To write a Word macro

In Word for Windows, to write and run a macro containing ODBC calls, you execute the following steps. Specific versions of Word may vary slightly.

1. Install the WBODBC.WLL library.

Install the WBODBC.WLL library as described in the "Word Developer's Kit." Copy it into the START subdirectory where Word is installed. This way, the library loads automatically every time you run Word.

2. Make the library available to the template.

Make the WBODBC.WLL library available to the template that you used to create the Word document. To do this, select "Template..." from the File menu, then click "Add" and select the path where the library is stored. Make sure the file-type box says "Word Add-Ins" and not "Document Templates." This process adds the library to the list of available models. To make WBODBC.WLL available to your macros, be sure to check the box beside the library name in the list.

3. Type the source code for your macro.

To do this, select "Macro" from the Tool menu, type the name of the macro you are going to create, and then click the "Create" button. Now, you can type your WordBasic code.

There are several ODBC functions provided with this library. A complete list of them is included in Appendix B of the "Word Developer's Kit."


Note: You must declare all functions that you use in your macro at the top of the code, before the "SUB MAIN" specification. Otherwise, you will receive an error message during execution.


Here is an example showing how to use the SQLOpen Function:

Declare Function SQLOpen Lib
 "WBODBC.WLL"(connect_name$,
 output_string$, driver_prompt
 As Integer) As Integer
....
sub main
....
connect_num = SQLOpen("DSN=acuwin", output_ref$, 0)
....
Save the macro using the File menu "Save As" command. See the next step for suggestions about file names.

4. Execute the Macro.

There are several ways to invoke macros from Word. You can run them from a toolbar, or associate them with a key or menu choice. But easier still for the end user is to invoke the macros automatically using some standard macro names that are activated by Word under certain circumstances.

Here is a list of these macros:


AutoExec Runs when Word is activated
AutoNew Runs when a new document is created
AutoOpen Runs when a document is opened
AutoClose Runs when a document is closed
AutoExit Runs when Word is closed