Excel VBA 2007 Tutorial
Microsoft Visual Basic for Applications (VBA) is a subset of Visual Basic specifically designed for you to be able to customize Microsoft Office products like PowerPoint, Word, and Excel. If there isn't a button on the toolbar that fits your needs, or if you find yourself wishing there were a way to automate certain features (for example, opening documents automatically when Excel starts), then VBA is the tool for you.
Instructions
-
-
1
Press "Alt" and "F11" at the same time from the Excel window to launch the visual basic editor.
-
2
Double-click "ThisWorkbook" in the left navigation panel, under the Microsoft Excel Objects folder. This will open a blank code window.
-
-
3
Write the VBA code you want to run in this workbook. For example, you might write:
MsgBox("Alert!") -
4
Press "F5" to run the code. If the Run Macro dialog appears, click the "Run" button. If you use the example code, you will see the alert box pop up.
-
1
Tips & Warnings
If you want to run your VBA code at the press of a button, then make sure you assign a hotkey to the macro when you first see the Run Macro dialog in Step 4.
Check Microsoft's "New to Development" article for examples of different pieces of code you can run in the VBA window.
The VBA code you write only attaches to one workbook. In other words, if you want to run the same code in another workbook, you'll have to copy and paste the code over.
References
- Photo Credit computer image by Ewe Degiampietro from Fotolia.com