Free Support Forum - aspose.com

Looking for the sample vba code to display TOC automatically

Hi Folks. Love your product.

I have one problem that is bedeviling me however. A company document I generate must be protected. Also, of course, it must have a table of contents. If I lock it, the user cant hit CTRL A and then F9 to make the TOC show up.

Also, I want to find that propsoed VBA macro that makes a generated document create a TOC when it is first opened. I cant find that on your website.

Also, I am looking for some instructions in producing this desired result.

Also, if you can tell me whether it actually works...cause I havent seen anything written by anyone who actually is doing this successfully.

This is the last thing I have to do for this project, unfortunately it is coming up just when we are about to go live. Hopefully you can help me out.

Thanks for a great product. And I am looking forward to your answer.


This message was posted using Aspose.Live 2 Forum

Hi

Thanks for your inquiry. You can use a macro to automatically update the field. See the following link for more information.
http://support.microsoft.com/kb/832897

Also see the attached document and the following code.

// Open template that contains macro for updating fields

Document doc = new Document("in.doc");

DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a table of contents at the beginning of the document.

//……………………………………………………………………………………

// Build document

//……………………………………………………………………………………

// Protect document

doc.Protect(ProtectionType.ReadOnly);

// Save document

doc.Save("out.doc");

Hope this helps.

Best regards.

Your instructions worked like a charm. Thank you!