• Custom Heading Styles (97) (97)

    Author
    Topic
    #404850

    I am required to use a client’s template to produce some specifications and other reports. In their wisdom the template authors have decided not to use Word’s built-in heading styles but have created their own. These styles are called “DW$_Heading 1, DW$_Heading 2 &c. and are not linked nor are they tied to a specific List Gallery.

    I attempted to link these styles using VBA (via the techniques discussed on the mvps.org website) and ran into problems. The styles did not exhibit the same behaviour as the Word built-in heading styles, most significantly they didn’t promote/demote levels as I would expect. For example, when a heading was changed from say a level 2 to level 4 the style didn’t change from “DW$_Heading 2” to “DW$_Heading 4” as I would expect to happen with properly linked Word built-in heading styles.

    My questions are:
    1. Is the behaviour I expect to see a special property of the word built-in styles?
    2. If 1, can I force this behaviour programatically for non built-in styles somehow? or
    3. If not 1, is there something missing from my code (attached) that would give me the behaviour I expect?

    The code used is an adaptation of the macro I use to set the built-in styles which seems to work well.

    regards
    Grant Cartledge
    Melbourne, Australia

    Viewing 3 reply threads
    Author
    Replies
    • #826812

      Grant

      Now isn’t that interesting… I was about to say that promote and demote works for all outline lists but you also assigned outline levels for use in the Outline View as well. There does appear to be a power struggle going on here. If you set all the DW Heads to .OutlineLevel = wdOutlineLevelBodyText then they can be promoted and demoted with the behaviour you expect but they disappear when showing levels in outline view and they don’t appear in a TOC built on outline levels.

      You may be able to force this behaviour programmatically but it may be easier to just build a template with style aliases to merge both variants of the style. If your template has a style called “Heading 1, DW$_Heading 1” then you really have one style which works consistently and you get around the clients template silliness.

    • #826813

      Grant

      Now isn’t that interesting… I was about to say that promote and demote works for all outline lists but you also assigned outline levels for use in the Outline View as well. There does appear to be a power struggle going on here. If you set all the DW Heads to .OutlineLevel = wdOutlineLevelBodyText then they can be promoted and demoted with the behaviour you expect but they disappear when showing levels in outline view and they don’t appear in a TOC built on outline levels.

      You may be able to force this behaviour programmatically but it may be easier to just build a template with style aliases to merge both variants of the style. If your template has a style called “Heading 1, DW$_Heading 1” then you really have one style which works consistently and you get around the clients template silliness.

    • #826842

      I agree with Andrew that it would probably be easier to just merge the client’s stuff with your own template, using the built in styles based on the client’s, using aliases.

      Obviously you don’t want to return the files to them that way, but here’s a way around that. Say you’ve put the client’s document into your own template, which has, as Andrew suggested, styles like “Heading 1, DW$_Heading 1”. Now, if you try to rename that style to strip out the “Heading 1”, Word (or VBA) won’t complain, but they won’t let you do it, either.

      But … if you save the file as RTF, and open it up in a text editor, you can pretty easily locate the style table and the definition for “Heading 1, DW$_Heading 1”. Delete the “Heading 1,” part. When you re-open the file in Word, Word will re-generate an actual Heading 1 style, but leave yours intact, with all the formatting.

      I don’t know the complexity of your documents, and I certainly can’t promise this will work without any problems, but if the strategy works for you, it’s the kind of thing that could be implemented pretty easily in Perl (from start to finish — opening the Word files, saving them as RTF, making the substitution, and opening them back up in Word). Then again, this client may not be worth the trouble.

      • #827216

        Just as a footnote, the poster specified Word 97, which I don’t believe combined style names in that manner. I’m not sure whether this makes the solution easier or more difficult.

      • #827217

        Just as a footnote, the poster specified Word 97, which I don’t believe combined style names in that manner. I’m not sure whether this makes the solution easier or more difficult.

        • #827231

          I don’t have access to Word 97 right now to check for sure (it’s at home), but I’m almost certain it supported style aliases.

          Here’s a link to info on the binary file format for Word 97, and it specifically mentions style aliases.

          http://www-aix.gsi.de/~bio/DOCS/wword8.html%5B/url%5D

          But I could certainly be mistaken.

          • #827429

            I’m using Word XP and discovered the following:

            As previously noted, promote and demote didn’t work on my custom headings. I was careful to make sure my headings were all associated with an outline level on the Styles | Paragraph dialog.

            In Word XP, in the Styles pane, if you click Modify on one of the built-in Heading styles, two context-sensitive options are promote and demote. This is not true on my custom styles KHeading 1, KHeading 2, etc. Even if I base them on Heading 1, Heading 2, etc. So there is clearly something hard coded about the built-in styles that is not apparently available to a custom style.

            I was able to use increase indent and decrease indent to promote and demote in the document.

            My custom headings did appear in the outline view in Word XP, probably because they were clearly associated with an outline level.

            My custom headings also did appear in a Table of Contents automatically, again probably because they were clearly associated with an outline level.

            What does all this tell you? I no longer have Word 97, so I don’t know if you’ll have the same results, but make certain each Heading is associated with a level in the paragraph dialog (not just in the numbering dialog). It’s something to try… shrug

            Kim

          • #827430

            I’m using Word XP and discovered the following:

            As previously noted, promote and demote didn’t work on my custom headings. I was careful to make sure my headings were all associated with an outline level on the Styles | Paragraph dialog.

            In Word XP, in the Styles pane, if you click Modify on one of the built-in Heading styles, two context-sensitive options are promote and demote. This is not true on my custom styles KHeading 1, KHeading 2, etc. Even if I base them on Heading 1, Heading 2, etc. So there is clearly something hard coded about the built-in styles that is not apparently available to a custom style.

            I was able to use increase indent and decrease indent to promote and demote in the document.

            My custom headings did appear in the outline view in Word XP, probably because they were clearly associated with an outline level.

            My custom headings also did appear in a Table of Contents automatically, again probably because they were clearly associated with an outline level.

            What does all this tell you? I no longer have Word 97, so I don’t know if you’ll have the same results, but make certain each Heading is associated with a level in the paragraph dialog (not just in the numbering dialog). It’s something to try… shrug

            Kim

        • #827232

          I don’t have access to Word 97 right now to check for sure (it’s at home), but I’m almost certain it supported style aliases.

          Here’s a link to info on the binary file format for Word 97, and it specifically mentions style aliases.

          http://www-aix.gsi.de/~bio/DOCS/wword8.html%5B/url%5D

          But I could certainly be mistaken.

        • #828028

          Jefferson

          Word has had style aliases for a long time and they were certainly in Word 97. I don’t know the value of Andrew’s char char macro running in earlier versions of Word but I will vouch for his use of aliases in Word 97.

        • #828029

          Jefferson

          Word has had style aliases for a long time and they were certainly in Word 97. I don’t know the value of Andrew’s char char macro running in earlier versions of Word but I will vouch for his use of aliases in Word 97.

    • #826843

      I agree with Andrew that it would probably be easier to just merge the client’s stuff with your own template, using the built in styles based on the client’s, using aliases.

      Obviously you don’t want to return the files to them that way, but here’s a way around that. Say you’ve put the client’s document into your own template, which has, as Andrew suggested, styles like “Heading 1, DW$_Heading 1”. Now, if you try to rename that style to strip out the “Heading 1”, Word (or VBA) won’t complain, but they won’t let you do it, either.

      But … if you save the file as RTF, and open it up in a text editor, you can pretty easily locate the style table and the definition for “Heading 1, DW$_Heading 1”. Delete the “Heading 1,” part. When you re-open the file in Word, Word will re-generate an actual Heading 1 style, but leave yours intact, with all the formatting.

      I don’t know the complexity of your documents, and I certainly can’t promise this will work without any problems, but if the strategy works for you, it’s the kind of thing that could be implemented pretty easily in Perl (from start to finish — opening the Word files, saving them as RTF, making the substitution, and opening them back up in Word). Then again, this client may not be worth the trouble.

    Viewing 3 reply threads
    Reply To: Custom Heading Styles (97) (97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: