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 > Creating new page content

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

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