Sequence of events for Word document open

I have a series of documents that are created with an attached template that includes an AutoOpen macro.  Amongst other things the macro sets the chapter number or appendix letter of the chapter based on data that is passed into a document variable.  That chapter number is used in the sections of the document that appear in the table of contents. 

If that document is saved and then re-opened without the AutoOpen macro running (by holding down the Shift key), the document looks like it did when it was saved.  The chapter number will be present in the title and TOC.   However, if I open the document in code, even if I DisableAutoMacros(1), the chapter number is no longer present, reverting instead to template default in the TOC of 0.1, 0.2 etc.

Can anyone explain this?  Is there a way to open the document without running the AutoOpen but still have the information present?

Office 2013

Windows 7

What is the code in the AutoOpen macro?

Possibly, you should be using an AutoNew macro in the template instead of an AutoOpen. 

Hope this helps,
Doug Robbins - MVP Office Apps & Services (Word)
dougrobbinsmvp@gmail.com
It's time to replace ‘Diversity, Equity & Inclusion’ with ‘Excellence, Opportunity & Civility’ - V Ramaswamy

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

The AutoOpen code does some formatting, but the code related to this issue reads a value for the chapter type (chapter or appendix) and the chapter number or appendix letter.  It then sets ActiveDocument.Styles("Heading 1").ListTemplate.ListLevels(1).StartAt,  .NumberStyle and .NumberFormat as appropriate.  The Table of Contents is updated after this.  This code works just dandy. 

To the issue at hand, when the document is saved, the chapter title and number is correct.  When the document is opened from a command line, for instance, without running the AutoOpen macros, the document looks like it did when it was saved.  When the document is opened in code, it looks like the ListLevels items have reverted to zero.  Is there any way in .Net code to open that document and get the saved contents as they appear when opening from Windows Explorer?  Can anyone explain what is going on that those two cases look so different?

I don't think AutoNew will help in this case.  The document is a chapter in a set of training course chapters.  These chapters can be renamed and reordered several times before they are completed. 

Any help is appreciated.

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated July 3, 2023 Views 639 Applies to: