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

Objects

Objects in macros represent OneNote's notebook/section/page hierarchy as well as the contents of a OneNote page.

Querying Objects

Macros can query objects using QueryObjects function and modify their properties:

ExpandForEach ($Text in QueryObjects("Text", GetCurrentPage())) If ($Text.highlightColor == "yellow") $Text.highlightColor = "green"

Macros can also create new pages and insert content on a page:

// Create a page at the end of the first section of the current notebook $Page = InsertObject(GetCurrentNotebook().sections[0], "Page", -1) // Create an Outline and a Paragraph $Page = GetCurrentPage() $Outline = InsertObject($Page, "Outline", -1) $Paragraph = InsertObject($Outline, "Paragraph", 0) $Paragraph.text = "Below is a table" // Now create a table $Table = InsertObject($Outline, "Table", -1) $Row = InsertObject($Table, "Row", -1) $Cell = InsertObject($Row, "Cell", -1) $Paragraph = InsertObject($Cell, "Paragraph", -1) $Text = InsertObject($Paragraph, "Text", -1) $Text.value = "First" $Text.bold = true // Add More text in this paragraph InsertObject($Paragraph, "Text", -1).value = " cell" // Add more cells InsertObject($Row, "Cell", -1).text = "A second cell"

Following is the list of objects macros recognize with the hierarchical structure:

Hierarchy Objects

Notebook
  │
  ├─ Section
  │    │
  │    └─ Page
  │
  └─ SectionGroup
       │
       └─ ·····
            │
            └─ SectionGroup
                 │
                 └─ Section
                      │
                      └─ Page

Page Objects

Page
  │
  ├─ Image
  │    │
  │    └─ Tag
  │
  ├─ EmbeddedFile
  │    │
  │    └─ Tag
  │
  ├─ Title
  │    │
  │    └─ Paragraph
  │            │
  │            └─ Tag
  │
  └─ Outline
       │
       └─ Paragraph
            │
            ├─ Tag
            │
            ├─ Text
            │
            ├─ Image
            │
            ├─ EmbeddedFile
            │
            └─ Table
                 │
                 ├─ Column
                 │
                 └─ Row
                      │
                      └─ Cell
                           │
                           └─ Paragraph
                                │
                                ├─ Tag
                                │
                                ├─ Text
                                │
                                ├─ Image
                                │
                                ├─ EmbeddedFile
                                │
                                └─ Table
                                     │
                                     └─ ·····

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