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 > Functions > Macro Execution Functions > SaveChanges

SaveChanges

Saves any changes made by this macro to OneNote. After changes are saved, all objects within any modified pages are invalidated. That is, if there are variables that are holding objects within such a page (e.g. Outlines, Paragraphs, Text objects etc.) they will be invalid and should not be used again. To get to those objects again, access them through a Page object. Objects within unmodified pages are unaffected.

Macros normally save any changes they made to OneNote at the end of macro execution, except if the execution is terminated by a call to ExitMacro(false). Therefore, it is typically not necessary to use this function. However, there are some cases where you may want to save changes before macro execution ends. For example this function can be useful to obtain certain properties that will only be available after saving changes or to provide incremental updates to the user.

Syntax

void SaveChanges()

Parameters

This function has no parameters

Examples

// Insert a paragraph into the first outline of the current page $page = GetCurrentPage() $outline = $page.outlines[0] $paragraph = InsertObject($outline, "Paragraph", 0) // Add some bold text $text = InsertObject($paragraph, "Text", -1) $text.value = "bold text" $text.bold = true // If we want to get the id or hyperlink for this paragraph, // we can't at this point, since these are only set by OneNote // after the changes are saved // This would return empty string: $id = $paragraph.objectId // Now save the changes we made SaveChanges() // At this point all page objects are invalidated // Do not access $outline, $paragraph, $text anymore as they are invalid // We can get them from the page again: $outline = $page.outlines[0] $paragraph = $outline.paragraphs[0] // Now we can get the id of this paragraph $id = $paragraph.objectId

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