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) : 15756
Screenshot :

Search & Replace

Find what
Replace with
Changelog :

June 20, 2016 (F98703) - Omer Atay
Re-written with the new Macro Language to take advantage of cleaner syntax and performance improvements

These versions are no longer supported:
November 06, 2013 - Omer Atay
Added option to search under Current section, Current notebook and All notebooks

March 02, 2013 - Omer Atay
Initial version


Dan - 2016-11-24
Thank you so much Omer,

You have been a great help as always.

It's really helpful for me to do all my stuff in onenote, otherwise I
Have to copy and paste pages and pages to word, then do it there, then bring back to onenote, so its a lot of work every day, but this will help me.

Thank you and have a good day :)
Omer Atay - 2016-11-23
Dan: You are using variables $i and $j which you haven't even initialized. What are you expecting to get from $Term[$i] and $Term[$j]? You could perhaps do something like:
$SearchArray = Array(1, 2, 3)
$ReplaceArray = Array("A", "B", "C")
$i = 0
While ($i < Array_Length($SearchArray))
    $Search = $SearchArray[$i]
    $Replace = $ReplaceArray[$i]
    // Do what you need to do here
    $i += 1
Dan - 2016-11-23
Hi Omer,

I am trying to use only 2 Arrays : 1 for all my Search terms and 1 for all my replace terms,
I have got stuck for hours :(

<?xml version="1.0" encoding="utf-16"?>
<Macro name="Search & Replace Array " category="Test" description="" publishDate="00-00-00T00:00:00.000Z" version="14">
  <Comment text="--------------------------------------------" />
  <Comment text="Search &amp; Replace - Using 2 Arrays" />
  <Comment text="--------------------------------------------" />
  <Expression>$Terms[0] = Array(1, 2, 3)</Expression>
  <Expression>$Terms[1] = Array("A", "B", "C")</Expression>
  <ForEach var="Term">
    <Expression>$Search = $Term[$i]</Expression>
    <Expression>$Replace = $Term[$j]</Expression>
    <ForEach var="Text">
      <Array>QueryText(GetCurrentPage(), $Search, true)</Array>
      <Expression>$Text.value = $Replace</Expression>

Can you spot the error?
Thank you :)