The Macro Recorder is a very powerful tool that lets you record a complex series of keystrokes and replay them directly inside your VB6 or VBA Editor in Microsoft Office, Access, Excel, etc.. It's ideal for situations where the same set of tasks need to be repeated.
To start, select macro recorder from the Total Visual CodeTools menu or toolbar:
The Macro Recorder Toolbar appears:
These buttons are available:
Button | Feature |
---|---|
Start Recording Press this then enter your keystrokes. |
|
Stop Recording This is enabled after you press the start button. When you're done with your series of keystrokes, press this button. |
|
Play This is enabled after you press the Stop Recoding button. Move your cursor to the location where you want to repeat your keystrokes, then press Play. Your keystrokes are repeated exactly the way you originally entered them. |
FYI, the appearance of the buttons may differ based on your Windows and VB6/VBA version but the order is always the same.
Note that the Macro Recorder only records keystrokes and not references to the menu or mouse movements and clicks.
Here's a simple example of how you may can use the macro recorder. Let's say we want to copy fields from one table to another. This is the code we want to write:
Dim dbs As DAO.Database Dim rstSource As DAO.Recordset Dim rstTarget As DAO.Recordset Set dbs = CurrentDb Set rstSource = dbs.OpenRecordset("tblSource") Set rstTarget = dbs.OpenRecordset("tblTarget") Do While Not rstSource.EOF rstTarget![FirstFieldName] = rstSource![FirstFieldName] rstTarget![SecondFieldName] = rstSource![SecondFieldName] rstTarget![ThirdFieldName] = rstSource![ThirdFieldName] rstTarget![LastFieldName] = rstSource![LastFieldName] rstSource.MoveNext Loop
But before we wrote that code, we only had the list of fields inside the Do..Loop:
Do While Not rstSource.EOF FirstFieldName SecondFieldName ThirdFieldName NextFieldName LastFieldName rstSource.MoveNext Loop
Rather than manually entering the text for each line, wouldn't it be easier to do it just once for the first line and repeat it for the others?
It's simple! Move the cursor to the beginning of FirstFieldName, then record the keystrokes necessary to convert that line to this:
rstTarget![FirstFieldName] = rstSource![FirstFieldName]
Start by pressing the Start Recording button. Enter the keystrokes to create the first line from the field name, then move to the same place on the next line:
Keystrokes | Action and Line Appearance |
---|---|
<type> |
FirstFieldName |
Shift End | Highlight text to copy: FirstFieldName |
Ctrl C | Copy field name to the clipboard |
Left | Go to the beginning of the highlighted text |
rstTarget![ | Enter the first part of the line: rstTarget![FirstFieldName |
End | Go to the end of the line |
] = rstSource![ | Enter the second part: rstTarget![FirstFieldName] = rstSource![ |
Ctrl V | Paste the field name: rstTarget![FirstFieldName] = rstSource![FirstFieldName |
] | Finish the line: rstTarget![FirstFieldName] = rstSource![FirstFieldName] |
Home Down | Move to the beginning of the next line |
Press the Stop Recording button to save our keystrokes.
Pressing the Play button replays our keystrokes, and presto, the next line of code is written:
rstTarget![SecondFieldName] = rstSource![SecondFieldName]
Press Play for the next line, and next line, etc., and you quickly get the desired result:
rstTarget![FirstFieldName] = rstSource![FirstFieldName] rstTarget![SecondFieldName] = rstSource![SecondFieldName] rstTarget![ThirdFieldName] = rstSource![ThirdFieldName] rstTarget![NextFieldName] = rstSource![NextFieldName] rstTarget![LastFieldName] = rstSource![LastFieldName]
This example is fairly simple. For more complex repetitive steps, the Macro Recorder will ensure accuracy and save you tons of time!
Supports Office/Access 2016, 2013, 2010, 2007, 2003, 2002, 2000, and Visual Basic 6.0!
Also available for
Access 97
"Total Visual CodeTools is by far my favorite third-party product."
Alison Balter, Author, Conference Speaker, Instructor
Best Visual Basic Add-In
Rave Reviews