Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    2 Star Lounger
    Join Date
    May 2006
    Location
    Currently in Europe
    Posts
    103
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Detect TOC "content control"

    I have a macro that iterates through a Word text. One of the things it does is to detect and skip fields, depending on their type. This way the macro skips any TOC it comes across.

    In newer versions of Word, inserting a TOC from the references tab places the TOC field in something that looks like a content control. My macro can't digest this object, and crashes.

    I created a test macro that detects a normal content control, yet it does not detect this object that the TOC field is in.

    What is this object? How can I detect it?

    I'm grateful for any help or references!
    Stylus

  2. #2
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,049
    Thanks
    124
    Thanked 119 Times in 116 Posts
    You are right that it is not simply the field. I'm not sure what it is, but you can insert the field directly by copying it from the inserted object, undoing the insertion of the TOC, and then pasting the field back in.

    Version of Word? I just tested this in Word 2010.
    Charles Kyle Kenyon
    Madison, Wisconsin

  3. #3
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,049
    Thanks
    124
    Thanked 119 Times in 116 Posts
    It also works to directly insert the field. Insert > Quick Parts > Field > TOC. This does not use the DocPartGallery.
    Last edited by Charles Kenyon; 2016-01-09 at 09:04.
    Charles Kyle Kenyon
    Madison, Wisconsin

  4. #4
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,049
    Thanks
    124
    Thanked 119 Times in 116 Posts
    I don't know enough to help here. Here are screen shots of XML from the same document with Tables of Contents inserted from the References button and directly as a field.

    It is possible that vba has not caught up to the DocPartGallery yet. A Google search for "vba word docgallerypart" returns NO RESULTS! Likewise one for simply "docgallerypart." I expect that this thread may end up being the only hit for a while.
    Attached Images Attached Images
    Last edited by Charles Kenyon; 2016-01-08 at 15:34.
    Charles Kyle Kenyon
    Madison, Wisconsin

  5. #5
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,049
    Thanks
    124
    Thanked 119 Times in 116 Posts
    I also note with some interest that the one with the field inserted directly is 7K larger than the one with the TOC inserted with the DocPartGallery. The second one actually has more text because it has the title "Contents" inserted.
    Charles Kyle Kenyon
    Madison, Wisconsin

  6. #6
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,049
    Thanks
    124
    Thanked 119 Times in 116 Posts
    Charles Kyle Kenyon
    Madison, Wisconsin

  7. #7
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,049
    Thanks
    124
    Thanked 119 Times in 116 Posts
    I took the liberty of asking about this in the Customizing Office forum. Here is that question:
    http://answers.microsoft.com/en-us/o...=1452285932060
    Charles Kyle Kenyon
    Madison, Wisconsin

  8. #8
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    I'd suggest inserting TOCs via Insert|Quick Parts|Field rather than via References|Table of Contents, as the 'content control' the latter uses adversely affects the document's TOC update performance quite significantly when the TOC has many entries.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  9. #9
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,049
    Thanks
    124
    Thanked 119 Times in 116 Posts
    I noticed a delay when constructing the TOC using the references button.
    Charles Kyle Kenyon
    Madison, Wisconsin

  10. #10
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,049
    Thanks
    124
    Thanked 119 Times in 116 Posts
    Update on Google search. Today a search for DocPartGallery gives over 9000 results starting with MSDN articles.
    Charles Kyle Kenyon
    Madison, Wisconsin

  11. #11
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,049
    Thanks
    124
    Thanked 119 Times in 116 Posts

    Smile

    That search combined with vba turned up this thread on checking for existence of a Cover Page. It should help with the TOC problem initially posted. It is code by Paul Edstein (macropod).

    Code:
    If InStr(ActiveDocument.Content.WordOpenXML, "<w:docPartObj><w:docPartGallery w:val=""Cover Pages""/>") > 0 Then
      MsgBox "A Cover Page has been inserted."
    End If
    Charles Kyle Kenyon
    Madison, Wisconsin

  12. The Following User Says Thank You to Charles Kenyon For This Useful Post:

    Stylus (2016-01-11)

  13. #12
    2 Star Lounger
    Join Date
    May 2006
    Location
    Currently in Europe
    Posts
    103
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Wow! Thanks guys!

    All my templates have a TOC created with a field. That's more the result of a "legacy mind" at work than cleverness...

    The thing is that the macro in question is a conversion macro that assigns in-house styles to feral text... it grows and grows so that it can handle all the, um, Creative Formatting that it has to digest. Recently it has had indigestion from these TOC quasi-controls. They appear in text created by some of our pioneers here in the office, who instead of using mere templates would rather Boldly Go Where No One Has Gone Before... =8-/

    I had Googled extensively before posting here, yet I had not thought of checking the xml... Thanks for that idea Charles. Also the code snippet from Paul may lead to something.

    To give you some idea of the things this macro has to handle: the office intranet has an application called Confluence which can create, edit and store text. It also has an "export to Word" function which creates text that looks like Word text... sort of... only, it adds a blank line at the end of the "Word" text that HAS NO STYLE DEFINITION. None! This gives the macro a heart attack. I had to build an error trap leading to "Normal" being assigned. Whew!
    Stylus

  14. #13
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,049
    Thanks
    124
    Thanked 119 Times in 116 Posts
    Glad to have helped. If you can, get your folks using templates. You are a brave person to have undertaken such a task.
    Charles Kyle Kenyon
    Madison, Wisconsin

  15. #14
    2 Star Lounger
    Join Date
    May 2006
    Location
    Currently in Europe
    Posts
    103
    Thanks
    7
    Thanked 0 Times in 0 Posts
    You flatter me! Consider what a fine line separates bravery from stubborn foolishness...

    What intrigues me is why Microsoft has put the TOC field in this sort-of content control. What is the intention? Does it add some functionality?

    I know, I know... wrong line of questioning regarding Word!
    Stylus

  16. #15
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Quote Originally Posted by Stylus View Post
    What intrigues me is why Microsoft has put the TOC field in this sort-of content control. What is the intention? Does it add some functionality?
    The TOC Building Block (not a content control, per se), adds a 'Contents' or 'Table of Contents' heading, for example, that you'd otherwise have to add manually. A lot of overhead for a trivial benefit IMHO.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  17. The Following User Says Thank You to macropod For This Useful Post:

    Charles Kenyon (2016-01-13)

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •