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

Creating new page content

With macros you can create new pages and new content on pages in OneNote. The InsertObject function allows creating new pages, outlines, paragraphs and tables.

Creating new pages

To create a new page, you need to insert a new Page object to a Section object. You can specify where in the section you want to create the new page:

// Create a new page at the top of the current section // The last parameter is position and it is 0 based index InsertObject(GetCurrentSection(), "Page", 0) // Now create another one at the bottom InsertObject(GetCurrentSection(), "Page", -1) // Now create another one after 3rd page. It will be the // 4th page in the section, so specify the position #3 InsertObject(GetCurrentSection(), "Page", 3)

Creating new page content

You can create new page content in an existing page or a newly created page. Simply add more InsertObject functions to create the new objects. After creating each object, you can modify its properties or create more content below it:

// Create an Outline and a Paragraph in the current page $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"

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