Tutorial

Getting Started with Macros

Macro Editor

User Interface

Menus and Toolbar

Editing Macro Statements

Expression Editor

Macro Debugging

How To

Using variables

Finding and modifying objects

Creating new page content

Asking for user input

Storing persistent data

Using binary data

Sorting objects

Macro menus

Bulleted and numbered lists

Sample Macros

Concepts

Expressions

Objects

Properties

Variables

Data Types

Arrays

Functions

Literals

Operators

Comments

Last updated on: March 19, 2023
Also available as a single HTML file

Onetastic Macro Documentation > How To > Finding and modifying objects

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 second section in the first notebook $Section = GetNotebookRoot().notebooks[0].sections[1]

Reference

Statements

For

ForEach

If

Else If

Else

Switch

Case

Default

While

Expression

Comment

Break

Continue

Return

Hierarchy Objects

NotebookRoot

Notebook

SectionGroup

Section

Page

Page Objects

Title

Outline

Table

Column

Row

Cell

Paragraph

Text

Image

EmbeddedFile

Tag

Other Objects

DialogBox

MacroMenu

Window

Functions

Array Functions

Color Functions

Data Store Functions

Date/Time Functions

Dialog Box Functions

Macro Execution Functions

Macro Menu Functions

Object Functions

String Functions

Window Functions