Tutorial

Getting Started with Macros

Macro Editor

User Interface

Editing Macro Statements

Expression Editor

How To

Using variables

Finding and modifying objects

Creating new page content

Asking for user input

Sorting objects

Macro Logging

Sample Macros

Concepts

Expressions

Objects

Properties

Variables

Data Types

Arrays

Functions

Literals

Operators

Comments

Finding and modifying objects

Macros typically work by finding objects in OneNote and modifying their properties. There are several functions that provide direct access to notebooks, sections and pages in OneNote as well as provide ability to search through them. Following macro demonstrates these functions:

// Functions to get the current page, section, section group or notebook $CurrentPage = GetCurrentPage() $CurrentSection = GetCurrentSection() $CurrentSectionGroup = GetCurrentSectionGroup() $CurrentNotebook = GetCurrentNotebook() // You can also access the notebook root which stores all the notebooks $NotebookRoot = GetNotebookRoot() // If you want to search some objects, you can do so $Images = QueryObjects("Image", $CurrentPage) // You can also search text // Case sensitive $AllInstancesOfTheWordOnetastic = QueryText($CurrentPage, "Onetastic", true) // Case insensitive $AllInstancesOfTheWordOnetastic = QueryText($CurrentPage, "Onetastic", false) // Once you have an object, you can go up to find its parent or ancestors $FirstOnetastic = $AllInstancesOfTheWordOnetastic[0] ExpandIf (GetParentOfType($FirstOnetastic, "Paragraph", $ParentParagraph)) // Found the parent paragraph ExpandIf (GetAncestorOfType($FirstOnetastic, "Notebook", $ContainingNotebook)) // Found the containing notebook

Accessing object properties

To read or modify properties of objects, you can use the property accessor operator (.).

// Get the name of the current section $Name = GetCurrentPage().name // Modify the section name and color $CurrentSection = GetCurrentSection() $CurrentSection.name = "new name" $CurrentSection.color = "yellow" // Get the first section in the second notebook $Section = GetNotebookRoot().notebooks[0].sections[1]

Reference

Statements

ForEach

If

Else

While

Expression

Comment

Break

Continue

Hierarchy Objects

NotebookRoot

Notebook

SectionGroup

Section

Page

Page Objects

Title

Outline

Table

Column

Row

Cell

Paragraph

Text

Image

EmbeddedFile

Tag

Other Objects

DialogBox

Functions

Array Functions

Date/Time Functions

Dialog Box Functions

Macro Execution Functions

Object Functions

String Functions