A user recently sent an email asking if it is possible to run a macro from a custom toolbar button. Here is the response:
Yes, you
can add a macro to a toolbar button. I don’t think
the syntax to run a macro from a toolbar button has been documented, and it
took me a while to sort it out.
- Create and test your
macro.
- If you don't remember your macro name, you can use Tools -> Macro -> Edit Macros. This opens the
script editor, with the Macro tab selected. Each macro begins with Sub and
ends with End Sub. At the beginning of each macro are comments with the macro
name, shortcut and description. You can edit any of these to change the macro name, description or shortcut. After
modifying the macro, use File->Save from the script editor window to
save the changes.
- Open the menu designer
from the Tools menu. Expand the Toolbar node. Click on the main Toolbar
item. At the bottom, click the New button and select “normal button”.
- When the new button
properties panel opens, add a tooltip if you want, and click Select Image
to select an icon for the button.
- In the Action field,
enter [#2999#NameOfYourMacro]. The square brackets [ ] are important.
- This causes the menu
processor to execute the built-in command 2999, which is the value of the MACRO_RUN_LAST built-in constant. Since 2999 is in the
range of MACRO_RUN_FIRST (2000) to MACRO_RUN_LAST (2999), the macro name after the 2nd
“#” will be the name of the macro to execute. If you have multiple toolbar
button macros, you could use 2998, 2997, etc. as the ID after the first “#”.
|