TutorialGetting Started with MacrosMacro EditorUser InterfaceMenus and ToolbarEditing Macro StatementsExpression EditorMacro DebuggingHow ToUsing variablesFinding and modifying objectsCreating new page contentAsking for user inputStoring persistent dataSorting objectsSample MacrosConceptsExpressionsObjectsPropertiesVariablesData TypesArraysFunctionsLiteralsOperatorsComments |
Last updated on: February 06, 2021
Also available as a single HTML file Onetastic Macro Documentation > How To > Finding and modifying objects Finding and modifying objectsMacros typically work by finding objects in OneNote and modifying their properties. There are several functions that provide direct access to notebooks, sections and pages in OneNote as well as provide ability to search through them. Following macro demonstrates these functions: // Functions to get the current page, section, section group or notebook
$CurrentPage = GetCurrentPage()
$CurrentSection = GetCurrentSection()
$CurrentSectionGroup = GetCurrentSectionGroup()
$CurrentNotebook = GetCurrentNotebook()
// You can also access the notebook root which stores all the notebooks
$NotebookRoot = GetNotebookRoot()
// If you want to search some objects, you can do so
$Images = QueryObjects("Image", $CurrentPage)
// You can also search text
// Case sensitive
$AllInstancesOfTheWordOnetastic = QueryText($CurrentPage, "Onetastic", true)
// Case insensitive
$AllInstancesOfTheWordOnetastic = QueryText($CurrentPage, "Onetastic", false)
// Once you have an object, you can go up to find its parent or ancestors
$FirstOnetastic = $AllInstancesOfTheWordOnetastic[0]
![]() ![]() Accessing object propertiesTo read or modify properties of objects, you can use the property accessor operator (.). // Get the name of the current section
$Name = GetCurrentPage().name
// Modify the section name and color
$CurrentSection = GetCurrentSection()
$CurrentSection.name = "new name"
$CurrentSection.color = "yellow"
// Get the second section in the first notebook
$Section = GetNotebookRoot().notebooks[0].sections[1]
|
ReferenceStatementsForEachIfElseWhileExpressionCommentBreakContinueReturnHierarchy ObjectsNotebookRootNotebookSectionGroupSectionPagePage ObjectsTitleOutlineTableColumnRowCellParagraphTextImageEmbeddedFileTagOther ObjectsDialogBoxFunctionsArray FunctionsColor FunctionsData Store FunctionsDate/Time FunctionsDialog Box FunctionsMacro Execution FunctionsObject FunctionsString Functions |