1 General TOC use and creation
2 For WordWebNav, the intended TOC format is Word's default format
2.1 VBA limitations in changing TablesOfContents.Format
WWN Development Document
MS Word’s Table of
Contents :
research notes for TOC-use in WWN
Word’s Navigation pane shows the table-of-contents (View : Show : Navigation pane).
· Contents:
o Research notes for Word’s TOC, for use in:
§ The WWN navigation pane
§ generate_word_html.docm, whose VBA program adds a TOC to a Word document
· Also see: word-html--bugs-and-fixes.docx
o Section: 1.1 Word TOC HTML
This document was created by the WWN author for his own use in developing WWN. It is included in the WWN repo, as other developers may find it useful.
· TOC Tips and Tricks
o http://wordfaqs.ssbarnhill.com/TOCTips.htm
· How to create a table of contents in Microsoft Word | ShaunaKelly.com
o https://shaunakelly.com/word/numbering/tableofcontents.html
· Tables of contents (Word's Numbering Explained)
o https://wordmvp.com/FAQs/Numbering/NumberingExplained/NumberingInAction/TOC.htm
· TOC Tips and Tricks
o http://wordfaqs.ssbarnhill.com/TOCTips.htm
o TOC formatting
§ By default, the TOC styles are very bland. They are based on the Normal style, which means that, unless you have modified Normal, this is what you'll get:
· Word 2003 and earlier: All entries will be 12-point Times New Roman, single-spaced, with no Space Before or After. Each TOC style below TOC 1 is progressively indented. That is, TOC 1 is flush left; TOC 2 has a 0.17″ left indent, TOC 3 has a 0.33″ left indent, and so on.
· Word 2007 and above: All entries will be 11-point Calibri with 1.15 line spacing and 5 points Spacing After. Each TOC style below TOC 1 is progressively indented. That is, TOC 1 is flush left; TOC 2 has a 0.15″ left indent, TOC 3 has a 0.31″ left indent, and so on.
§ Effect of direct formatting
· I have said that by default Word’s TOC styles are very plain. If you haven’t changed them in any way and you see text that is different, then this is coming from your headings. TOC entries do not reflect any formatting that is part of a heading style, but they can pick up any font formatting that is applied directly. So, for example, if your Heading 1 style is defined as 16-point Arial Bold and your Heading 1 paragraph is 16-point Arial Bold, then the TOC entry for that paragraph will still be 12-point Times New Roman or 11-point Calibri. But if you change the formatting of part of the heading, making one of the words italic, for example, then that change will be reflected in the TOC entry.
· Example of bold formatting from heading causing TOC to be formated as bold
o computer-concepts--original.html
o The TOC formatting has problems, but due to the document's flawed formatting
§ Heading levels used are 1 and 8
§ Many of the heading instances have one-off formatting changes made to them
o When TOCs are generated by Word, one-off heading changes are incorporated into the TOC
§ Described here:
· http://wordfaqs.ssbarnhill.com/TOCTips.htm
· Section: "Effect of direct formatting"
· This appears to be why the TOC is bold
· Formats
o "From template" apparently means to use the default TOC-related sytles defined for the document (apparently defined in Normal.dot). Apparently,
§ The document's TOC styles (e.g., TOC 1 to TOC 9) are, collectively, the TOC "format" ("Formats" in the GUI)
§ When the document is created, the document's TOC styles are copied from those defined in Normal.dot.
· Normal.dot's TOC styles are the Word default TOC styles, unless those TOC styles have been altered in Normal.doc
· In VBA, TablesOfContents.Format will be WdTocFormat.wdTOCTemplate
§ The document's TOC format can be changed by using the Formats drop-down in the GUI, and picking something other than "From template", e.g., simple
· Those TOC styles are copied to the document's TOC styles
· In VBA, TablesOfContents.Format will be changed to the enumeration for the selected format, e.g., wdTOCSimple
· If a TOC is created later, and "From template" is specified, then the document's current TOC styles will be used
o The styles in Normal.dot are not reloaded
o Similarly, in VBA, TablesOfContents.Format cannot be changed to wdTOCTemplate by assignment statement
o Word's default TOC-related sytles seem to work best for WordWebNav.
o Word provides other Formats to choose from, e.g., Modern, Simple, etc. but they don't seem to work as well, if at all, for WordWebNav
o https://www.bitchute.com/video/i5kg033feX2V/
§ Word provides several predefined table-of-contents formats, including Classic, Formal, and Simple. The default format is “From template,” which takes the table of contents styles from whatever template is attached to the document. If this is the Normal template (the default), the “From template” styles create a table of contents in which the headings are title case (important words have initial capital letters). You can format a table of contents manually as you would any other text in Word—by selecting text and then applying character or paragraph formatting or styles.
· If Formats is chosen to be anything other than "From Template", e.g., Modern, it appears that the chosen Format's TOC styles are added to the document, and they replace the prior TOC styles
o Later, in the GUI, chosing "From Template" does not revert the TOC styles to the default TOC styles (from Normal.dot)
o "Using Microsoft Word 2002" By Bill Camarda:
· The document's TOC styles apply to every TOC in the document. TOCs in the same document cannot use different TOC sytles
· If a Format other than From Templates is used, it is possible to revert to the default TOC-related styles
o To do this, use Word's Style Manager to delete the the current TOC-related styles, and to copy in the TOC-related styles from Normal.dot
o Click on Styles : Manage Styles : Import/Export
o Remove the document's TOC sytles: under the Styles tab, select TOC 1 to TOC 9 for the document (left window), then Delete
o Add the TOC styles from Normal.dot:
o Selecting Formats "From Template" should now create a TOC with the default TOC styles
§ These are the "defaults" defined in Normal.dot
§ Usually, they are also Word's TOC defaults
o Also, In VBA, TablesOfContents.Format will now be WdTocFormat.wdTOCTemplate
· The document's overall TOC properties are in: ActiveDocument.TablesOfContents
o The Format property is: ActiveDocument.TablesOfContents.Format
§ https://docs.microsoft.com/en-us/office/vba/api/word.wdtocformat
o .Format can be changed to one of the defined Formats, e.g.,
§ wdTOCModern 4 Modern formatting.
o However, if .Format is not wdTOCTemplate, it cannot be changed to wdTOCTemplate
§ wdTOCTemplate 0 Template formatting.
§ For example, the second assignment statement will run, but it will not change the .Format property:
ActiveDocument.TablesOfContents.Format = wdTOCModern
ActiveDocument.TablesOfContents.Format = wdTOCTemplate
o If a TOC is added using Formats "From Template", and a macro recorded, the generated VBA code will set the .Format property to wdIndexIndent
§ This use of wdIndexIndent appears to be a bug. It is not a defined for the .Format property
· WdIndexType enumeration (Word) | Microsoft Docs
o https://docs.microsoft.com/en-us/office/vba/api/word.wdindextype
§ It appears that the VBA code should use wdTOCTemplate instead.
§ wdIndexIndent is 0, which is also what wdTOCTemplate is.
§ Also, that generated VBA is probably pointless, because if .Format is not wdTOCTemplate, .Format cannot be changed to wdTOCTemplate
· And, presumably, .Format is set to wdTOCTemplate by default
· With WordWebNav, if TablesOfContents.Format is not wdTOCTemplate, the TOC style might not work properly
o A possible solution is to change the TOC format to the Word default form, described above
o As an experiment, I created a macro to make that change, but the VBA code refers to specific file-paths, so I didn't further pursue development of that VBA code, though it's probably possible
Application.OrganizerCopy Source:= _
"C:\Users\jimyu\AppData\Roaming\Microsoft\Templates\Normal.dotm", _
Destination:= _
"D:\Documents\Professional-projects\My-web-site-development\Word-to-HTML\automation-dev\testing\test-Word-files\my-Word-files\headings-and-bullets--format-modern--test.docx" _
, Name:="TOC 1", Object:=wdOrganizerObjectStyles
· In WordWebNav's VBA code for creating a TOC and Word HTML, the code checks if:
o ActiveDocument.TablesOfContents.Format = wdTOCTemplate
o If not, a warning message is issued
o The VBA code does not attempt to change ActiveDocument.TablesOfContents.Format to wdTOCTemplate
· Summary
o It might be a better way of generating the TOC frame for WWN, than what is used now
· Apparently was a prominent feature in Word 2003
o Several docs describe it, and it's easy to generate
o Later, it seemed to get dropped as a prominent feature
§ No longer seems discussed much
§ It's difficult to find info on how to activate it, e.g.,
· How-to
§ Current use is a bit different, e.g., file names are different
o Bootlegged books?
§ https://flylib.com/books/en/2.952.1.192/1/
· "Special Edition Using Microsoft Office Word 2003" By Bill Camarda
§
· Example
o headings-and-bullets--format-frames.docx
§ Primary doc
§ From here click on "Table of Contents in Frame"
· Creates the other 2 doc files:
o headings-and-bullets--format-frames--added.docx
§ Has the 2 frames
§ TOC frame's contents appears to come from 1 Level 1.docx
§ Body frame's contents appears to come from headings-and-bullets--format-frames.docx
o 1 Level 1.docx
§ Has TOC
§ Save As HTML (filtered), creates:
· 1 Level 1.htm
· headings-and-bullets--format-frames.htm
· headings-and-bullets--format-frames--added.htm
o The primary HTML
· MS docs references
o TablesOfContents object (Word) | Microsoft Docs
§ https://docs.microsoft.com/en-us/office/vba/api/word.tablesofcontents
§ TablesOfContents.Format property (Word) | Microsoft Docs
· https://docs.microsoft.com/en-us/office/vba/api/word.tablesofcontents.format
§ WdTocFormat enumeration (Word) | Microsoft Docs
· https://docs.microsoft.com/en-us/office/vba/api/word.wdtocformat
§ TablesOfContents.Add method (Word) | Microsoft Docs
· https://docs.microsoft.com/en-us/office/vba/api/word.tablesofcontents.add
o TableOfContents object (Word) | Microsoft Docs
§ https://docs.microsoft.com/en-us/office/vba/api/word.tableofcontents
· TOC tutorials and reference documents
o Word Macro Examples & VBA Tutorial - Automate Excel
§ https://www.automateexcel.com/vba/word/macro-examples#Paragraph
o Examples
§ Word References - VBA Code
· https://bettersolutions.com/word/references/vbacode.htm
· If TablesOfContents properties are changed, it appears that Update must be run for all of the document's TOCs
o vba - Word TOC update not working correctly - Stack Overflow
§ https://stackoverflow.com/questions/38519654/word-toc-update-not-working-correctly
o Updating an Entire TOC from a Macro (Microsoft Word)
§ https://word.tips.net/T000301_Updating_an_Entire_TOC_from_a_Macro.html
· Adding and removing paragraph, to allow adding a TOC
o Word Paragraphs - Inserting Text
§ https://bettersolutions.com/word/paragraphs/vba-inserting-text.htm
o Accessing Paragraphs in a Macro (Microsoft Word)
§ https://word.tips.net/T000823_Accessing_Paragraphs_in_a_Macro.html
o Moving to the Start or End of the Real Document (Microsoft Word)
§ https://word.tips.net/T000826_Moving_to_the_Start_or_End_of_the_Real_Document.html
o Jumping to the Start or End of a Document (Microsoft Word)
§ https://word.tips.net/T000120_Jumping_to_the_Start_or_End_of_a_Document.html
· Attempting to remove the empty paragraph that I create, but apparently it gets included with the TOC range, so it can't be removed
o How to detect that a Paragraph.Range is inside a TOC in a C# Word AddIn - Stack Overflow
· pesticide-report.docx
o TOC add failed, apparently due to top-of-document being an h1 heading
§ Solution:
· insert empty paragraph at top of document
· move selection to top of document
· add paragraph
o Added paragraph could not be deleted
§ I tried several techniques
§ It appears that the paragraph is made part of the TOC's range
· Macro-generated TOC vba-code has bugs and superflous code
o wdIndexIndent is not defined for the .Format property
§ Value: 0
§ https://docs.microsoft.com/en-us/office/vba/api/word.wdindextype
o wdTOCTemplate is defined, value 0
§ https://docs.microsoft.com/en-us/office/vba/api/word.wdtocformat
With ActiveDocument
.TablesOfContents.Add Range:=Selection.Range, RightAlignPageNumbers:= _
True, UseHeadingStyles:=True, UpperHeadingLevel:=1, _
LowerHeadingLevel:=9, IncludePageNumbers:=False, AddedStyles:="", _
UseHyperlinks:=True, HidePageNumbersInWeb:=True, UseOutlineLevels:= _
True
.TablesOfContents(1).TabLeader = wdTabLeaderDots
.TablesOfContents.Format = wdIndexIndent
End With
· TOC field codes
o vb.net - How to create an automatic table of contents in word using Visual Basic 2010 - Stack Overflow
o vba - word table of contents - Stack Overflow
§ https://stackoverflow.com/questions/17158221/word-table-of-contents
o Field codes: TOC (Table of Contents) field - Office Support
o TOC Switches
§ http://wordfaqs.ssbarnhill.com/TOCSwitches.htm#FurtherReading
· The Compatibility Checker GUI is not shown by generate_word_html.docm
· MS-tech-report--Sequential File--original.doc
· MS-tutorial--Deep Learning--original.docx
· computer-concepts-instructors-manual.docx