Onetastic Macro Documentation >
How To >
Each macro adds a button to the ribbon to run the macro. Optionally, macros
can display a menu in the ribbon for more options. For example, Function
macro displays the following menu:
Macro menus can be static or dynamically generated based on user's usage patterns. For instance
a macro like Search and Replace may display the
recently used search and replace terms in the menu.
Both static and dynamic menus are created by the Setup function. Setup function is a user defined
function in a macro which will get called whenever Onetastic needs to get a macro's menu to be displayed
in the ribbon. Below is a sample Setup function:
Setup function always has a single parameter byref
$menu. This parameter is
an object of type MacroMenu. You can then use the MacroMenu_AddItem function to add menu
items. A macro with this Setup function will have the following menu:
Each menu item is associated with an argument that will be passed to Main function when
user clicks on that menu item. In this case if user clicks the first menu item, Main function
for this macro will be called with the argument "arg1".
Setup function will get called every time Onetastic needs to refresh the menu for each macro.
This can be after a macro execution, after a macro is edited, or after a new macro is downloaded.
To avoid performance problems, Setup function should do minimal work and should not be running for
a long time. Setup function for a macro will get aborted if it runs long and the menu for that
macro will not be visible. Setup function also cannot access OneNote content or show dialog boxes.
Macro editor makes it easy to create a setup function quickly via the following menu:
This will create a sample Setup function which you can use to quickly edit. If a Setup
function already exists, this will switch to it.
As macro menu items pass arguments to the main function, you may want to debug the execution
of your macro with such arguments. The debug button in the Macro Editor toolbar has a split
menu that makes it easy to pick the menu items and debug their execution:
This menu will display each menu item and clicking on one of them will start the debugger
with the associated argument passed to the Main function.