TOC in Current Page

Description : Creates a table of contents from heading in the current page and inserts at the top of the page. Optionally it adds "Back to Top" links to the headings.

Download

TOC in Current Page


You need Onetastic Add-in
for OneNote to run this macro.
Download Onetastic
Author(s) : Omer Atay
Category : TOC
Last Updated : September 04, 2016
Rating :
(10)
Download(s) : 18603
Screenshot :

TOC in Current Page

Changelog :

September 04, 2016 - Omer Atay
Now finds all the headers in the page, even if they are in a table.

August 16, 2016 - Omer Atay
Re-added the option for "Back to Top" links, which was lost in the previous update.

July 30, 2016 - Omer Atay
TOC now uses indents based on heading level so that it can be collapsed

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

July 24, 2014 - Omer Atay
Added the option for "Back to Top" links.

March 17, 2013 - Omer Atay
Initial version

Comments

Name
Comment
Kun - 2017-02-24
Hi Omer,

Thanks for your tool, it saved my huge amount of time.
However, as I usually add more information in the same page, is it possible to add a function to update the TOC?
Currently, if I launch the tool in the second time, it will only add one more TOC on the top of page.

Many thanks,

Kun

Dan - 2017-02-13
Thank you So Much  Omer,

You trully are a good guy!
Yay it worked  -  now  I can put a # any where I need and like magic it will make a TOC for me :)

I had 50 headings 1 in one page  - that really upset me when I had to do it manually one by one.

Quick one the back to top link does not work - it does not go back to top  im not sure why :(

Omer Atay - 2017-02-12
Dan: Read your macro log which should say something like:
------------------------------------------------------------------------
// Set its indent based on the heading style
------------------------------------------------------------------------
$Inserted_Paragraph.indent = (String_Substring($Paragraph.style, 1, 1) - 1)
Evaluating expression: $Paragraph.style
Value: <empty>
Evaluating expression: String_Substring($Paragraph.style, 1, 1)
Value:  (string)
Error while running macro: Macro contains an error

'-' operator requires operands to be of type Numeric
------------------------------------------------------------------------

Here the macro is trying to set the indent of the TOC entry based on its heading level and this expression is being evaluated:
    String_Substring($Paragraph.style, 1, 1) - 1
$Paragraph.style is empty so String_Substring returns empty string. So the expression that is evaluated is:
    "" - 1
This expression cannot be evaluated because you cannot subtract 1 from an empty string. As the error reads: '-' operator requires operands to be of type Numeric

Previously the macro was finding paragraphs that have heading style. For them $Paragraph.style would be something like "h3". If we evaluate that expression again;
    String_Substring($Paragraph.style, 1, 1) - 1
$Paragraph.style is "h3" so String_Substring returns "3". So the expression that is evaluated is:
    "3" - 1
which is valid because string "3" can be implicitly converted to numeric type of value 3.

In your case you probably don't need to set the indent for the TOC entry if you don't have any heading levels.