Copy link to clipboard
Copied
I am working with code to update a single TOC in a document. Do you have to select the text frame where the existing TOC resides before updating the TOC? Here’s the code and errors:
var curDoc = app.activeDocument;
tocStyle = curDoc.tocStyles.itemByName("Default");
curDoc.createTOC(tocStyle, true);
Errors:
Invalid value for parameter ‘using’ of method ‘createTOC’. Expected TOCStyle, but received nothing.
Before creating toc you have to add atleast one style in table of contents style and then save that style.
If you are using defoult style you can use tocStyles[0].
var curDoc = app.activeDocument;
tocStyle = curDoc.tocStyles[0];
curDoc.createTOC( tocStyle , true);
Copy link to clipboard
Copied
".. received nothing" means exactly that. If you print out the value of tocStyle, it will say "undefined"; you do not have a TOCStyle named "Default". Try with "...tocStyles [0]" instead (the top item, regardless of how it's called).
Copy link to clipboard
Copied
Before creating toc you have to add atleast one style in table of contents style and then save that style.
If you are using defoult style you can use tocStyles[0].
var curDoc = app.activeDocument;
tocStyle = curDoc.tocStyles[0];
curDoc.createTOC( tocStyle , true);
Copy link to clipboard
Copied
Both of your answers are correct. Thank you, Jongware and payalm68947498.