Extending VBA with the Windows API

VBA can use the same Windows functions used by C programmers to extend VBA dramatically. I have found the best code on Visual Basic sites (eg VBNet or DevX), and it can usually be pasted straight into VBA with few if any changes.

Generally, you need to declare the Windows functions you need at the top of the module, then use them in your code (carefully, of course). Here are some examples.

Launching programs

This code launches a program, and optionally waits for it to finish before letting VBA continue (something Shell can't do). It also gives you the handle of the program.

This code will launch files (like Excel or Word documents) and figure out for itself what application to launch them in

Registry

This code will let you set and get registry keys.

Setting file dates

This code lets you change the date/time on files.

Registering ActiveX files programmatically

Here

Create Windows shortcuts programmatically

Here (it does proper shortcuts, which is REALL hard, and also a simpler version which uses the IE shortcut format)

 

 

 

 

 

Note: Where possible, I've attributed ideas to the people who thought of them. If I have missed someone or made a mistake, please let me know.