>GRSoftware >VBA Tutor >Newsletter Tutorials >Tutorial 8 >Tutorial 10

VBA TUTOR NEWSLETTER ~ TUTORIAL NINE:
Using Declarations to make API [ Application Program Interface ] calls


If you are going to do some serious VBA programming, you will need to learn how to make API calls that use the inbuild functions of the various WINDOW'S dll's.
To find out more about API's go to www.vbapi.com, which has an excellent reference section, as well as an excellent article called 'Beginner's Guide to the Windows API'.
OR ... look at Win32 API @ MSDN.

STEP ONE: Declare the API 'function' or 'sub' in a module.

You can make the declaration either in a new module inserted into the document you are working on, or you can place it in a module in the 'normal.dot' template so it will be available to all documents.

Public Declare Sub mciSendStringA Lib "winmm.dll" (ByVal lpstrCommand As String, ByVal lpstrReturnString As Any, ByVal uReturnLength As Long, ByVal hwndCallback As Long)

'This Sub makes a call to inbuilt functions of 'winmm.dll'


STEP TWO: Create the buttons and insert the code:

Create two buttons, one labled "Open CD Door", and another labled "Close CD Door".

In 'Design Mode', double click on the "Open CD Door" button and insert the following code.

mciSendStringA "Set CDAudio Door Open", 0&, 0, 0

Then, double click on the "Close CD Door" button and insert the following code.

mciSendStringA "Set CDAudio Door Closed", 0&, 0, 0

Now save the document, exit 'Design Mode', and try the buttons.

NOTE: Your computer must of course have a CD Drive!

Further examples can be found at ...


HOPEFULLY, THESE CODE EXAMPLES WILL ADD TO YOUR ABILITY TO BECOME A VBA POWER USER!
© 2000 Gary Radley