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 |
|||||
---|---|---|---|---|---|---|---|---|
Author(s) | : | Omer Atay | ||||||
Category | : | TOC | ||||||
Last Updated | : | December 07, 2020 | ||||||
Requirements | : | OneNote 2010 or above | ||||||
Watch this short video to learn more about this macro | ||||||||
![]() ![]() |
||||||||
Screenshot | : | |||||||
![]() TOC in Current Page |
||||||||
Changelog | : | December 07, 2020 (10CBCC) - Omer Atay May 28, 2018 (CF836A) - Omer Atay April 24, 2018 (1B3508) - Omer Atay December 17, 2017 (EA5512) - Omer Atay September 04, 2016 (157AED) - Omer Atay August 16, 2016 (C55DB0) - Omer Atay July 30, 2016 (A20BF1) - Omer Atay June 20, 2016 (E0E260) - Omer Atay These versions are no longer supported: July 24, 2014 - Omer Atay March 17, 2013 - Omer Atay |
----
This is a bug in OneNote. They fixed it in a newer version. Depending on what version you have, you might be able to switch to that new version by setting a registry key (see below). The alternative to that is to wait until the new build is deployed or don’t use light text colors in tables.
Registry key to create:
HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\OneNote
Name: OverrideVersion
Type: REG_DWORD
Value: 1
---
Obviously you take your life into your hands when editing the Registry. Back up everything - EVERYTHING - make your will, etc. and don't do any of these things to be safest.
I have tables on my page where the header font is bold and white. Every single time I run TOC in Current Page, the header font changes from white to grey. No exception.
So far, this doesn't seem to affect any other text on my page, but it's all default-coloured, i.e. text is black, headings are bley, and so forth.
The links created only works on the desktop version. It does not work on the iOS version.
Thanks for creating this for individuals and organized their notebooks!
Tried it once and it worked beautifully!! Tried again on same page, new page, deleted entire notebook and tried again, different type of page etc... didn't work every again.
What gives?!
sullivan.andrew: Unfortunately currently macros cannot create list numbers.
This can be fixed by re-running the macro... but unfortunately the macro doesn't refresh the "Back to Top" links even if the TOC content was updated to work for the page it's on. All of the "back to top" links still go to the original page. So the true fix is to run this twice, once with "back to top" unchecked to delete all of the "back to top" links, then again with "back to top" option checked which rebuilds.
I should not have to jump through this many hoops to copy a page with a page specific TOC.
Update with two suggestions as mentioned by "AJ - 2017-09-26" would be great and ease working on documents which are long and undergo frequent updates.
[I'm assuming this would require the script to search for text with the same formatting as the custom style, unless custom styles uses custom tags behind the scenes]
Just two minor things
a) Would love to see an option to quickly update the TOC (if I leave the ToC at the top and untouched, one click update would belovely)
b) I am starting to get very annoyed by the "Popup" that asks me about "Back to Top links". Can I set that to remember my selection somehow or not ask me every single time
Since, I find myself deleting and then recreating the ToC a fair bit on the pages that I am actively working on.
Love your work. I am actually waiting for then it prompts me so I can purchase it (I know it'll happen :-)
Best!
Can't figure out the reason. Already deleted all formats before defining the headers which do not contain ink/handwriting.
Or is it possible to find/replace a specific tag with a heading?
Or, find/replace a specific word with a heading?
When I'm typing during class it is too hard to click CTRL-ALT-1 or CTRL-ALT-2 and yet I need a TOC at the top of each page so I can quickly scan pages to find information. Right now I type ttt1 or ttt2 and then use your "search & tag" to replace with a TOC1 or TOC2 tag. However, I can't get those to the top of the page to create a TOC because "tag summary for specific tag" only works at the section level.
Its not there right now!!
Heading 1
Some text
Heading 2
Some more text
The TOC comes out as:
Table of Contents
Heading 2
Heading 1
:)
I am new to Macros. I downloaded Onetastic and m able to use one calendar.I dont know how to use TOC. Can anyone provide a link /info on how to use it ?
I created a headlines with # and Subheadlines with ## but that doesnt seem to create TOC after I hit TOC tab on my ribbon.
Please Help.
The only other thing is that, if I have the "Back to Top" links too, regenerating a TOC with the BtT links means each header on the page will then have 2 BtT's: a dead one & a Live one. :-(
BTW, do you know if Microsoft intends to fix the bug you mentioned?
So whether you move or copy a section with its pages to another notebook destroys the "TOC in Current Page" links.
Can this be fixed?
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
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 :(
------------------------------------------------------------------------
// 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.
Hi Omer,
It said operand requires a "-"
I could not understand it all
<Macro name="TOC in Current Page - Test" category="TEST" description="" publishDate="00-00-00T00:00:00.000Z" version="15">
<Comment text="----------------------------------------------------------------------------------" />
<Comment text=" TOC in Current Page" />
<Comment text="----------------------------------------------------------------------------------" />
<Comment text="" />
<Comment text="Ask user if they want "Back to Top" links" />
<Expression>$dialogBox = DialogBox_Create("")</Expression>
<Expression>DialogBox_AddCheckBox($dialogBox, "Add (Back to Top) links", "top", false)</Expression>
<Expression>DialogBox_Show($dialogBox)</Expression>
<Expression>$top = $dialogBox.controls["top"]</Expression>
<Comment text="If they want "Back to Top links" get a link to top" />
<Expression>$Page = GetCurrentPage()</Expression>
<If>
<Condition>$top</Condition>
<Expression>$topLink = QueryObjects("Paragraph", $Page)[0].hyperlink</Expression>
</If>
<Comment text="Now go through each outline and find all the headings" />
<Expression>$HasParagraphs = false</Expression>
<Expression>$outlines = $Page.outlines</Expression>
<If>
<Condition>Array_Length($outlines) > 0</Condition>
<Expression>$firstOutline = $outlines[0]</Expression>
</If>
<Expression>$i = 0</Expression>
<ForEach var="outline">
<Array>$Page.outlines</Array>
<Expression>$Paragraphs = $outline.paragraphs</Expression>
<ForEach var="Paragraph">
<Array>$Paragraphs</Array>
<Expression>$ParagraphsToCheck = Array()</Expression>
<Comment text="Check if this paragraph has a table, if so look into it" />
<If>
<Condition>$Paragraph.contentType == "table"</Condition>
<ForEach var="TableParagraph">
<Array>QueryObjects("Paragraph", $Paragraph)</Array>
<Expression>Array_PushBack($ParagraphsToCheck, $TableParagraph)</Expression>
</ForEach>
</If>
<Else>
<Expression>Array_PushBack($ParagraphsToCheck, $Paragraph)</Expression>
</Else>
<Comment text="Find heading styled paragraphs" />
<ForEach var="Paragraph">
<Array>$ParagraphsToCheck</Array>
<If>
<Condition>!String_Contains($Paragraph.text, "#", false) || ($Paragraph.text == "")</Condition>
<Continue>1</Continue>
</If>
<Expression>$HasParagraphs = true</Expression>
<Comment text="Insert a new paragraph for this TOC entry" />
<Expression>$Inserted_Paragraph = InsertObject($firstOutline, "Paragraph", $i)</Expression>
<Comment text="Set its indent based on the heading style" />
<Expression>$Inserted_Paragraph.indent = (String_Substring($Paragraph.style, 1, 1) - 1)</Expression>
<Comment text="Add the text and a hyperlink" />
<Expression>$Text = InsertObject($Inserted_Paragraph, "Text", -1)</Expression>
<Expression>$value = $Paragraph.text</Expression>
<If>
<Condition>String_EndsWith($value, " (Back to Top)", true)</Condition>
<Expression>$value = String_Substring($value, 0, (String_Length($value) - 14))</Expression>
</If>
<Expression>$Text.value = $value</Expression>
<Expression>$Text.hyperlink = $Paragraph.hyperlink</Expression>
<Expression>$i += 1</Expression>
<Comment text="Insert a "Back top Top" link if it was requested" />
<If>
<Condition>$top && !String_EndsWith($Paragraph.text, " (Back to Top)", true)</Condition>
<Expression>$Texts = Array(InsertObject($Paragraph, "Text", -1), InsertObject($Paragraph, "Text", -1), InsertObject($Paragraph, "Text", -1))</Expression>
<Expression>$Texts[0].value = " ("</Expression>
<Expression>$Texts[1].value = "Back to Top"</Expression>
<Expression>$Texts[1].hyperlink = $topLink</Expression>
<Expression>$Texts[2].value = ")"</Expression>
<ForEach var="Text">
<Array>$Texts</Array>
<Expression>$Text.fontSize = 9</Expression>
</ForEach>
</If>
</ForEach>
</ForEach>
</ForEach>
<Comment text="Add a title if we had any entries" />
<If>
<Condition>$HasParagraphs</Condition>
<Expression>InsertObject($firstOutline, "Paragraph", $i)</Expression>
<Expression>$Title = InsertObject($firstOutline, "Paragraph", 0)</Expression>
<Expression>$Title.text = "Table of Contents"</Expression>
<Expression>$Title.bold = true</Expression>
<Expression>$Title.fontSize = 16</Expression>
</If>
</Macro>
This is yours I only chnaged the #
I really need this as i have sooo many headings and the page is long , please help thank you
is it possible i can Make TOC out of all the paragraphs that contain a #
instead of headings?
I paste from word and all the heading 1 gets lost then i have to manually apply it in one note and i have so many pages :(
TOC is interleaved.
- Onenote doc
Level 1-1
Level2-1
Level3 - 1
Level3 - 2
Level3 - 3
Level2-2
Level 1-2
-TOC
Table of Contents
Level3 - 1
Level3 - 2
Level3 - 3
Level2-1
Level2-2
Level 1-1
Level 1-2
Thanks for any help :)
Microsoft OneNote Version: 14.0.7149.5000 (32-bit)
Create a directory each time, will not cover the original directory.This can be perfect?
Also, I'd like to add a point in front of the directory. But I don't know how to set up.
Such as
* test1
* test2
(Star instead of a dot, or can be customized)
My English is very poor, it is the result of machine translation.Please forgive me.
Thank you
"Yes, I have not changed anything, neither to the headings nor to the rest of the pages. Could I send you a copy of such a page?"
Any ideas?
Meanwhile looks like when it got upgraded now level 3 and above headings get treated as level 2. How does one get all headings like before?
It creates:
Heading 1
Heading 2
Heading 3
Instead of:
Heading 1
Heading 2
Heading 3
A property named 'paragraphs' on object of type 'Outline' does not exit.
I'm sure that I have been used the built-in Styles -- the Heading1-6 styles
Please help me.
Thank you
Typical Error50: I have a 64-Bit System, but a 32-bit OneNote-Version. I tried to install/update your 64-bit Version, but it obiously cant update a Version which isn't compatible...
Thanks for your time!
BR, Bernhard
Thank you for your fast response! I checked as you described, and I found the Version 2.18.4 !
It might have to do with the admin-rights on this Computer. I'll re-check and give you a Feedback.
Best wishes,
Bernhard
After download and doubleclick, it tells me that "this macro is for a newer Version of Onetastic..." although i have the latest Version "Current version: 3.1.1 July 31, 2016" downloaded and it seemed it was installed. Where can i check the version which is installed?
Thanks and best wishes,
Bernhard
When creating a TOC I get an incorrect order of the corresponding text headings:
What is:
Heading A (header style 1)
Subheading A.1 indented (header style 2)
Subheading A.2 indented (header style 2)
Heading B (header style 1)
Subheading B.1 indented (header style 2)
Heading C (header style 2)
becomes a "Table of Contents":
Subheading A.1 indented (header style 2)
Subheading A.2 indented (header style 2)
Heading A (header style 1)
Subheading B.1 (header style 2)
Heading B (header style 1)
Heading C (header style 2)
What is:
Heading A (header style 1)
Subheading A.1 indented (header style 2)
Subheading A.2 indented (header style 2)
Heading B (header style 1)
Subheading B.1 (header style 2)
Heading C (header style 2)
becomes a "Table of Contents":
Subheading A.1 indented (header style 2)
Subheading A.2 indented (header style 2)
Heading A (header style 1)
Subheading B.1 (header style 2)
Heading B (header style 1)
Heading C (header style 2)
This only happens, when there are too many headings in the page.
But can this be fixed? I often have many headings in texts and would appreciate the macro to be capable of managing that.
Thanks!
Am I doing something wrong?
PS: is it possible always to replace the current TOC if TOC applied once more?
For having TOC appear on the side, try a second window: Ctrl + M then Ctrl + Alt + D
- I agree, this would be perfect.
2. When you click a heading from the TOC, you are directed to the section, but the heading of the section is at the bottom of your page. Is it possible to be directed to the section, but change the settings so the heading is at the top and you can start reading instantly without scrolling?
Windows 8. Onenote 2013. v 15.0.4753.1003
thankx
However one small problem - it will be nice if it ignores "(Back to Top)" portion of headings - as I like many other users in these comments have constantly changing pages and outlines.
Table of Contents
Heading1
Heading2
Heading 2 - another
becomes (after heading change and re-doing TOC)
Heading1 (Back to Top)
Heading2 (Back to Top)
Heading 2b - another (Back to Top)
Even though that text is now officially part of the heading name, could you please update the macro to remove those characters from the TOC?
Other than that, this macro is AWESOME!
However, I have yet to be able to use it--I have the OneTastic and Macros sections in the ribbon but can't seem to find a button anywhere...
Sorry if this is a silly question, but I downloaded the .onetastic file but can't seem to find it :/
Any suggestions?
I made a small enhancement on my local copy which improves the readability of long TOC's:
Instead of adding just "space" values to increase the indent of the sub-levels of the tree, I used a "|" sign:
<WhileVar name="i" op="gt" value="1">
<ModifyProp name="text" op="add" value=" | " />
Which then generates something like this:
Heading 1
| Heading 1.1
| | Heading 1.1.1
| | Heading 1.1.2
| | Heading 1.1.3
| | Heading 1.1.4
| Heading 1.2
| Heading 1.3
| | Heading 1.3.1
| | Heading 1.3.2
Heading 2
| Heading 2.1
Thank you for another fantastic article. The place else could anyone get that kind of info in such an ideal means of writing? I've a presentation next week, and I'm on the look for such info.
Suggest installing your three TOC macros in one go.
I didn\'t see the FAQ where it\'s clearly explained that the .onestatic file extension must be associated with MacroInstaller.exe.
Thanks.
Your onenote extension is great, but it seems that we can not donwload Macros on this site. Every-time, for every macros, the file downloaded is not a xml, but a text file of 32 bytes with a hash-code.
For this one for example, the file name is \"TOC in Current Page.onetastic\", but the content is 01C7C254D45E462CB24B3246853B3032.
For the Upper Macro, the content is 0622BB0FF9C4416EA2E65BD264C86472.
Tanks a lot if you could fix this !
the other TOC macros work fine, but this one doesnt for me.
maybe I can try to solve it myself, but would be thankfull for any idea.
thx