Microsoft Office Development and Consultancy
|Excel > Macros > Creating a Macro||< Previous | Next >|
Step 1 - How to Create a Macro
Recording your own macros can be very useful although there will be times when you want to write a macro from scratch.
Examples of good VBA code can be found on web sites and in newsgroups and forums which you might find useful.
You might want to use this code or modify the code to make it specific to the task at hand.
It is very easy to create a macro to allow you to enter (or copy and paste) the necessary code.
Step 2 - Using the Macro dialog box
Select (Tools > Macro > Macros) to display the Macros dialog box.
Enter the name in the Macro name box.
The default location for any macros you create is the active workbook.
Press Create to create the macro.
Step 3 - Insert or Write the Code
The Visual Basic for Applications window will be opened automatically.
You will see that a code module has been added to the active workbook and that the following code has been added:
You are now ready to insert or paste in you own VBA code.
Once you have entered your VBA code select (Debug > Compile) to make sure your code does not contain any syntax errors.
After you have finished you can return to Excel by selecting (File > Close and Return to Microsoft Excel).
Step 4 - Save your changes
Then select (File > Save) to save the macro in that workbook.
You can actually run the macro while you are in the Visual Basic Editor window by pressing F5.
You can also resize the windows so you can see them both at the same time.
You can then run the macro by selecting (Tools > Macro > Macros), selecting the name of the macro and pressing the "run" button.
Step 5 - Things to Remember
If you are writing VBA code then make sure the following two options are selected in your (Tools > Options)(Editor tab) of the Visual Basic Editor window: "Auto List Members" and "Auto Quick Info".
There is no comment provided automatically when you create a macro in Excel, only when you record a macro.
|© Better Solutions Limited 15-Oct-2013||< Previous | Top | Next >|