Search & Replace

Description : Search and replace text in the current page, section or notebook


Search & Replace

You need Onetastic Add-in
for OneNote to run this macro.
Download Onetastic
Author(s) : Omer Atay
Category : Find
Last Updated : June 20, 2016
Rating :
Download(s) : 12653
Screenshot :

Search & Replace

Find what
Replace with


Dan - 2016-10-19
Thank you Omer,
I was able to make it work  - with the
    <Array>QueryText($oParagraph, "Apple", true)</Array>
    <Expression>$Text.value = "Orange"</Expression>
Although thats a silly example  - I am able to replace real text, so its good for me to learn the basic expressions. Have a great Evening :)
Omer Atay - 2016-10-18
Dan: QueryText returns an Array of Text objects (Array<Text>) not a single Text object. Check the return type on the documentation. So in your code $FindText is an array of text objects and not a single text object because "Apple" may occur multiple times in a paragraph and you will get them all in an array. As a result you can't do $FindText.value, arrays don't have a value property. You can do this instead:
For each $Text in QueryText($Paragraph, "Apple", true)
    $Text.value = "Orange"
This will iterate over each text object with value Apple and set their value to Orange.
Dan - 2016-10-18
Hi Omer,

hope you are great  :)
I am trying to find paragraphs that begin with ZZ in that paragraph I would like to replace the word Apple with Plum as an example.

<?xml version="1.0" encoding="utf-16"?>
<Macro name="Search Paragraphs  - Containing Text" category="Test Macros" description="" publishDate="00-00-00T00:00:00.000Z" version="13">
  <Comment text="Replace in Paragraph that Begins with ZZ" />
  <ForEach var="Paragraph">
    <Array>QueryObjects("Paragraph", GetCurrentPage())</Array>
      <Condition>String_StartsWith($Paragraph.text, "ZZ", true)</Condition>
      <Expression>$FindText = QueryText($Paragraph, "Apple", true)</Expression>
      <Expression>$FindText.value = "Orange"</Expression>

is this the right way? I have looked at all the docs and examples and cant find a way to make it happen.