Friday, July 29, 2005

Recording our first Excel VBA Macro!

Recording Macros in Excel isn't difficult at all... and the great thing is, we can start learning a bit about programming in Excel by getting Excel to do the programming for us!
The Excel macro recorder is the best teacher that you can have and will remain the best assistant for the rest of your life.
Follow these instructions to create your first Macro: The Macro Recorder.(Tip: right-click on the link and choose 'Open in new Window'). Once we've recorded our Macro, see if you can find a way to look at the code that you've created! Can you understand the code?

After you've tested your first Macro a couple of times, see if you can make the following modifications to your code:
  • Modify your code so that the value that is put into cell A2 is 999 instead of 55, re-run your macro to test it!
  • Modify your code so that the font-size of cell A3 is set to 8 instead of 24, and again, re-run your macro.
  • Modify your code so that the background colour of cell A1 is something other than Blue. As usual, re-run your macro to make sure that your change worked!
Remember if you get stuck, you can always find help nearby! We'll also take a look at a few other features of VBA - such as the VBA editor, the VBA Debugger, With - End With statements and using buttons to trigger macros. These are all tools that we'll be using and re-using over the next term!

Some points you will want to file away in your mind:
  • What does VBA stands for?
  • Where or why is it used in Excel (and other applications)?
  • How did you get to the VBA editor from Excel?
  • What's the easiest way to figure out how write the code to do something in Excel VBA?
  • Why is Debugging useful?

0 Comments:

Post a Comment

<< Home