Recording

In most Microsoft Office applications you can record your own macros.
A recorded macro is the name given to a sequence of instructions or keystrokes that can be played back as a way of automating a particular tab.
Before you start recording it is often worth thinking about your actions before and maybe even rehearsing the steps you want to take.
Using the macro recorder is only useful for very simple macros.
Macros that use variables, looping or other types of control structures cannot be recorded and must be written.
It is worth remembering that an action will not be recorded until it has been completed and any dialog boxes have been dismissed.
They can be used to play back your actions and can prevent you from having to perform tedious or repetitive tasks.


Start Recording

When you record a macro the recorded code is placed in a module.
When you record a new macro a new code module is inserted into your current project.
Any subsequent macros will also be stored in this module assuming the file hasn't been closed and re-opened.
The author of your macro and the description are all added to the top of every recorded macro.
Displays the word "Recording" in the status bar.
SS
Subroutines will have the names Macro1, Macro2 etc


Stop Recording

You can stop recording by pressing the black square button on the Visual Basic toolbar or by pressing (Tools > Macro > Stop Recording).
The macro recorder has a tendency to generate more code than is actually needed.


Important

The tooltip of the Relative References button does not change to indicate which setting is currently selected. The only indication is whether the button has a sunken appearance or not.
You can switch to Relative Recording at any time by using the toggle button on the Stop Recording toolbar.
Which ever setting is selected when you press the Stop Recording button becomes the default the next time you record a macro. If you stop recording with relative references then relative references will be recorded the next time. If you close Excel then the setting is reset to absolute references.
To prevent your procedure macros from showing in the macro list prefix them with the word "Private" or you can add a dummy optional argument.
Always remember to stop the macro recorder. If you record yourself running the macro you will go into an infinite loop because the macro will call itself again and again.
Always clean up your code after it has been recorded as lengthy, unnecessary code is always included.
Manipulating Excel objects using Activate, Select and Selection is slow, error prone and usually difficult to maintain.


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext