Tutorial

Getting Started with Macros

Macro Editor

User Interface

Menus and Toolbar

Editing Macros

Macro Debugging

How To

Using variables

Finding and modifying objects

Creating new page content

Copying and moving objects

Asking for user input

Storing persistent data

Using binary data

Sorting objects

Macro menus

Bulleted and numbered lists

Accessing the file system

Accessing the clipboard

Sample Macros

Concepts

Expressions

Objects

Properties

Variables

Data Types

Arrays

Functions

Literals

Operators

Comments

Last updated on: June 21, 2025
Also available as a single HTML file

Onetastic Macro Documentation > Functions > Object Functions > InsertObject

InsertObject

Creates a new object and inserts it into OneNote hierarchy or into a OneNote page. Returns the newly created object. If you want to use an existing object to copy from, use CopyObject function.

Syntax

Object InsertObject(
	Object parent, 
	ObjectType type, 
	Numeric position)

Parameters

Object parent
Parent object to create the new object under.
ObjectType type
The type of the new object to create and insert. See remarks for the types of objects that can be inserted.
Numeric position
The position of the new object. The value is a 0 based index for the child collection or -1 to insert at the end.

Remarks

Following types of objects can be created, copied, and moved via InsertObject, CopyObject, and MoveObject functions. See descriptions of each function for specific conditions or differences in behavior:
Parent Object Child Object Types Remarks
Notebook SectionGroup Section Sections and section groups must have unique names inside a notebook. Section groups cannot be copied or moved. Sections cannot be moved.
SectionGroup SectionGroup Section Sections and section groups must have unique names inside a section group. Section groups cannot be copied, moved, or removed. Sections cannot be moved or removed.
Section Page
Page Outline Image EmbeddedFile To create a Title object under a page, simply access its "title" property.
Outline Paragraph Table Image EmbeddedFile An outline must have at least one child object.
Paragraph Text Tag Text objects can only be inserted at the beginning or end of a paragraph. Text objects cannot be moved or removed
Table Row A table must have at least one row.
Row Cell A row must have at least one cell. Every row in a table must have the same number of cells.
Cell Paragraph Table Image EmbeddedFile A cell must have at least one child object.
Image Tag Image must be a direct child of a page to insert tags. Images inside outlines cannot have tags. Insert the tag into the image's parent paragraph instead.
EmbeddedFile Tag Embedded file must be a direct child of a page to insert tags. Embedded files inside outlines cannot have tags. Insert the tag into the embedded file's parent paragraph instead.

Examples

Copied!
// 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

Hierarchy Objects

Page Objects

Other Objects

Functions

Array Functions

Clipboard Functions

Data Store Functions

Data Type Specific Functions

Date/Time Functions

Dialog Box Functions

File System Functions

Macro Execution Functions

Macro Menu Functions

Object Functions

Special Functions

String Functions

Window Functions