Tutorial

Getting Started with Macros

Macro Editor

User Interface

Menus and Toolbar

Editing Macros

Macro Debugging

How To

Using variables

Finding and modifying objects

Creating new page content

Copying and moving objects

Asking for user input

Storing persistent data

Using binary data

Sorting objects

Macro menus

Bulleted and numbered lists

Accessing the file system

Accessing the clipboard

Sample Macros

Concepts

Code Structure

Expressions

Objects

Properties

Variables

Data Types

Arrays

Functions

Literals

Operators

Comments

Last updated on: May 12, 2026
Also available as a single HTML file

Onetastic Macro Documentation > How To > Macro menus

Macro menus

Each macro adds a button to the ribbon to run the macro. Macros also will display a menu in the ribbon for more options. The top portion of ribbon button will invoke the default action for the macro and the bottom portion will display the menu. For example, Insert Monthly Calendar macro displays the following menu:

Insert Monthly Calendar macro 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.

Setup function

Macro 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:

Copied!
function Setup(byref $menu) MacroMenu_AddItem($menu, "arg1", "Menu Item 1", "Description for Menu Item 1") MacroMenu_AddItem($menu, "arg2", "Menu Item 2", "Description for Menu Item 2") MacroMenu_AddItem($menu, "arg3", "Menu Item 3", "Description for Menu Item 3")

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:

A macro menu

The menu items added by MacroMenu_AddItem is displayed under the Presets section and each macro gets a Manage section to display common actions like Rename or Change Icon. Each menu item added in the Setup function 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.

Menu sections

By default, menu items are added to the Presets section. You can place items in different sections by passing an optional fifth argument to MacroMenu_AddItem. The available sections are "Recent", "Presets", and "Settings". Sections are displayed in the menu in this order, followed by the fixed "Manage" section.

Copied!
function Setup(byref $menu) // Recent items (e.g. recently used values) MacroMenu_AddItem($menu, "search1", "Recent Search 1", \ "Last used search term", "Recent") MacroMenu_AddItem($menu, "search2", "Recent Search 2", \ "Second most recent term", "Recent") // Presets items (default section, no fifth argument needed) MacroMenu_AddItem($menu, "preset1", "Preset 1", "A preset option") // Settings items (e.g. configuration choices) MacroMenu_AddItem($menu, "colors", "Change Colors", \ "Customize display colors", "Settings")

A macro menu with sections

If a section has no items, its separator is automatically hidden. This means you only need to add items to the sections your macro actually uses.

Performance Considerations

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.

Creating and Editing Setup Function

Macro editor makes it easy to create a setup function quickly via the following menu:

Create Macro 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.

Debugging Menu Items

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:

Debugging Macro Menu

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.

Reference

Statements

Hierarchy Objects

Page Objects

Other Objects

Functions

Array Functions

Clipboard Functions

Data Store Functions

Data Type Specific Functions

Date/Time Functions

Dialog Box Functions

File System Functions

Macro Execution Functions

Macro Menu Functions

Object Functions

Special Functions

String Functions

Window Functions