Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Evil Word Styles (Word XP VBA)

    Hi, all. I know my problems are getting more esoteric, but maybe someone will have had a similar experience to my current dilemma.
    I wrote a piece of VBA code that will (ostensibly) remove all unused paragraph styles from a document. Normally, it works and has been working fine. The current problem is that there are three documents (so far) wherein the list of styles shown in Word's own Styles and Formatting window doesn't match the list array I obtain through code. I'm attaching a Word file with two screen-caps to illustrate this; the dialog box in the screen cap is the one I present to the user before nuking all the unused styles. Excuse the lousy format; I didn't anticipate that it might have to hold so many style names!
    To make matters more confusing in these documents, when the style All Text Char, which only turns up via my VBA code, is deleted, the style All Text is actually (also?) deleted from the document, even though it's used extensively: all paragraphs formerly using All Text are now in Normal.
    I've done all the usual trouble-shooting for possible document corruption and nothing changes the result.
    My two questions are: 1) Is there some reason that a document ends up with so many variations of styles with the word " Char" at the end? and 2) Does anyone know why All Text Char would show up as a valid style through VBA, but not in the Styles and Formatting window?
    (I'm assuming that the reason All Text is deleted has something to do with the fact that it is the style name that comes closest to matching the "unlisted" All Text Char.")
    Thanks for your help in advance.
    Attached Files Attached Files
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

  2. #2
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Evil Word Styles (Word XP VBA)

    Update:
    Since it's casual-devil-may-care-Friday, I decided to go exploring and opened an RTF version of the file using Notepad. When I searched for "All Text Char" (which is the name of the style that my code says is unused but whose existence is completely denied by Word's dialog boxes), it was found in the following string, in what I guess must be the style's definition: {*cs123 additive fs24lang1033langfe1033langnp1033langfenp1033 sbasedon10 slink70 styrsid15087775 All Text Char;}.
    I deleted that string, saved the RTF file with a new name, used Word's "Open and Repair" facility (because I'm pretty sure that I @#$!% up the style indices by deleting that string), and lo and behold! The problem "went away."
    So, I'm thinking that the list of styles that Word presents in the Styles and Formatting window is obtained in a way other than the one I used to collect style names in my code. Also, I'm a little surprised that Word's "Open and Repair" didn't help at all prior to this (although I'm finding that, while very useful, it's far from a panacea).
    Any other opinions? And any help as to why there tend to be so many styles like stylename Char Char in the documents I see?
    Oh, and just for grins, I'm attaching the code I used to find all unused styles.
    Attached Files Attached Files
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Evil Word Styles (Word XP VBA)

    > And any help as to why there tend to be so many styles like stylename Char Char in the documents I see?

    I think this is caused by the "Keep track of formatting" setting on the Tools>Options...>Edit tab. In the process of (mostly) returning Word 2002 back to the behavior of Word 2000, I turned that off.

    As for the more disturbing question of why Word deleted a Style "A" when you deleted Style "A Char", it sounds like a bug. Something you might want to report to someone, but who??

  4. #4
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Evil Word Styles (Word XP VBA)

    We encourage people in this department to turn that off, but what can you do.
    I thought, though, that that setting only affected what is in the Styles and Formatting pane, not what styles get created. Regardless, I think there's a definite disconnect between what gets displayed in the Styles and Formatting pane and what is really going on inside the document. I can't even think of a kludgy workaround for this potential problem.
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Evil Word Styles (Word XP VBA)

    Actually, I don't use that pane [sic]. I just opened it and noticed that All Styles doesn't necessarily mean ALL styles because you can customize the list to omit certain styles. (Customize... being the last option on the drop-down/pop-up at the bottom of the pane [sic].) Not sure where Word keeps track of THAT information, or whether it is accessible via VBA, or has anything to do with your example.

  6. #6
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Evil Word Styles (Word XP VBA)

    I, too, have discovered that "All Styles" doesn't necessarily mean all styles, just like a style listed under the "Styles in Use" doesn't mean it's actually being used in the document. (It means it has been used at one time.)
    But after more poking around, I've been able to establish the following:
    When I first open the doc, All Text Char doesn't show up in the Styles and Formatting pane, regardless of the Show: choice.
    All Text Char shows up if I choose Show: Custom... and click on the Styles button.
    Modifying All Text Char via Show: Custom... and clicking on the Styles button changes the appearance of paragraphs using All Text
    And the capper: If I modify All Text Char using that method of accessing it, and if I change the font attributes, the font attributes of the paragraph style All Text are modified and the character style All Text Char is now nowhere to be found!
    I can only conclude that either All Text Char wasn't supposed to be a "style" at all, but rather the character format of the paragraph style All Text... or else it was a style but that its definition was corrupted or incomplete.
    How this will help me with my project, I have no idea... <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

  7. #7
    Lounger
    Join Date
    Jan 2001
    Location
    Milton Keynes, Buckinghamshire, England
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Evil Word Styles (Word XP VBA)

    Jefferson,

    You associate the creation of ' Char' styles in Word 2002 (Word XP) with the 'Keep track of formatting option', but I don't think this is my experience.

    While I think I know what causes the appearance of ' Char' styles, I am still unclear how they seem to transform themselves subsequently from character styles (which is what they seem to be when they are born) into paragraph styles, which in turn can spawn a style ' Char Char' and so on. Mike's example shows one style with seven ' Char's.

    When you select anything within a paragraph, without selecting the whole paragraph, and apply a paragraph style to the selection, Word has always applied the font formatting associated with the paragraph style to the selection but without applying the paragraph style to the whole paragraph. This is the case with Word 97 and Word 2000.

    With Word 2002 it seems that this font formatting has been elevated to a character style, which is generated on the fly and is named by taking the name of the 'parent' paragraph style and adding ' Char' to the end. This would appear to be a 'feature' of Word 2002 and it would seem from some cryptic Word error messages I have seen that it might even have the name of a 'link' style. It is certainly the case, as Mike discovered, that if you attempt to delete one of these ' Char' styles, you will delete the paragraph style on which it is based, as well.

    What is still a mystery to me, however, is how these character styles seem to become paragraph styles themselves (and can then go on to produce ' Char Char' styles and so on). I have also been shown documents in which the suffix has been ' Char1', presumably because Word felt it needed to create one of these styles when a style of the same name already existed.

    Incidentally, I encourage Word users here to restore the 'Style' command to their Format menu in Word 2002 because the list it offers seems to be a more reliable indication of the styles that are genuinely present in the style sheet than the list in the Styles and Formatting task pane, which is also pushed into the 'Styles' drop-down list on the Formatting menu. While I think the Styles and Formatting tool bar is an excellent tool for identifying and locating all manner of strange formatting that may have been applied to a Word document, I prefer to use the existing methods to remove the formatting or re-apply the correct style.

    As for the 'Keep track of formatting option' itself, I don't really understand what it does.

    Any further information from yourself or any other colleagues in the lounge would be greatly appreciated.

  8. #8
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Evil Word Styles (Word XP VBA)

    I see what you mean, and I believe you're right.

    I applied "Heading 1" to a word in the middle of a Normal paragraph. This causes the "Heading 1" style to be "in use," but didn't change the Formatting toolbar's Font drop-down, or the Styles and Formatting pane's list. However, the "Heading 1 Char" does appear in the old-style Styles dialog, and if you press Ctrl+Shift+S and type head and arrow down though the list, it is there. I missed the evidence before.

    Since I never use paragraph styles as character styles, I hadn't picked up on this and have not looked for a solution. My main thought is, "don't do it." I generally apply direct formatting (gasp!) when I need to emphasize text in some way at odds with the paragraph style. While this might be less modern than using character styles, it's still faster, and speed is important to me. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  9. #9
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Evil Word Styles (Word XP VBA)

    <hr>I generally apply direct formatting (gasp!) when I need to emphasize text in some way at odds with the paragraph style. While this might be less modern than using character styles, it's still faster, and speed is important to me.<hr>
    Glad I'm not alone. <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15> I tend to shy away from character styles, too. Klaus Linke once tested to see if a document was less complex if character styles were used instead of direct formatting & found no difference. The only advantage that I can see to character styles is if you need to apply several types of direct formatting, besides the usual bold, italic, & underline. So if I wanted red, bold, italic, & double underline (why, I don't know) <img src=/S/grin.gif border=0 alt=grin width=15 height=15>, a character style would be faster...but not by much, as holding down Ctrl & pressing B, i, & Shift+D will apply the last 3.

  10. #10
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Winston-Salem, North Carolina, USA
    Posts
    224
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Evil Word Styles (Word XP VBA)

    I have actually found one good use for character styles. Other than this one use, I don't bother with them, because I don't think you get enough additional functionality to make them worth while. The one use I have found is in legal documents, which frequently include a list of definitions. Usually each definition is one paragraph, with the word to be defined at the beginning of the paragraph, and usually that word is formatted in some special way - bold, italic, etc. I have created a definitions character style, which is great in case you anticipate the attorney changing his mind (WHAT?) about how he would like to have the word to be defined formatted. Other than that, I think they're pretty useless.

    Lee Morgan

  11. #11
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Evil Word Styles (Word XP VBA)

    Good point, Lee. I guess whenever you have a repetitive element (such as words to be defined), it pays to have a character style. Otherwise, you have to use Find/Replace to make changes...which may take in other direct formatting that you don't want changed. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  12. #12
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Evil Word Styles (Word XP VBA)

    Well, one thing I have discovered after all this is the behavior of these funky styles.

    Based on your test, I created a style called "Steve". Then I highlighted a single word in a paragraph and selected that style (which is something that users will do, regardless of what they've been told.) Sure, enough, there was now a style called Steve Char (although as I said before, it doesn't appear in the Styles and Formatting task pane.) And then when I tried to delete it (by selecting Custom from the Show: drop-down box and clicking on the Styles button in the Format Settings window), it deleted both Steve Char and Steve.

    The two remaining questions are: Is there really a discrete Steve Char style when I apply that paragraph style to a single word? And how do documents then end up with paragraph styles called stylename Char Char which do show up in the list?

    In the meantime, I guess I will just modify my code so that it will only delete styles that end in "Char" if they are independent paragraph styles and not character styles.
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

  13. #13
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ANSWER TO Evil Word Styles (Word XP VBA)

    I finally got it!

    While trying to come up with a workaround so that I wouldn't blow away two styles at one time, I was writing a function to tell me the properties of the currently selected style. One of the properties I learned about was one call LinkStyle, which, according to the Help file "sets or returns a Variant that represents a link between a paragraph and a character style." Apparently, Microsoft WANTED a property that would behave exactly as described in this thread, and the LinkStyle property returns the name of the Paragraph style to which a given character style is linked.

    So, I found that I could trap for such a link and then re-set it to Normal, which is not deleted when the linked character style is deleted.

    Now, how those other styles ending in "Char Char" etc. became paragraph styles, I can't say for sure, but the evidence is pointing to the original template.

    Some days I feel like the guy with the broom walking behind the elephant.
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

  14. #14
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: ANSWER TO Evil Word Styles (Word XP VBA)

    > walking behind the elephant

    And not just any elephant: the biggest one in the business. <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15>

    If you could post the snippet that "saves" the paragraph style while deleting the Char version, I think that would be of use to many people.

  15. #15
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts

    CODE FOR ANSWER TO Evil Word Styles (Word XP VBA)

    I'm attaching the procedure that I ended up writing. There is a MAIN routine and an OKtoDelete() function that checks for unwanted "style-linking."

    In my original quest to remove unused styles from a document, just searching every story in a complex document (i.e. multiple sections) was hard enough, and was the subject of another posting I had on here a few months ago. That's why you will notice two searches being done for each style in the MAIN procedure. (There was a reason I used the selection object instead of a range object when searching the main story, but I forget what it was.) I did use the range object to search through headers, footers, etc.

    The function called OKtoDelete is called right before the unused style is added to the array of styles that will eventually be deleted. If the style is linked to the style NORMAL (which most are), the function returns TRUE. If it's one of those styles that end in CHAR, the .LinkStyle property is changed to NORMAL (if necessary) and then the function returns TRUE. In hindsight, the function could probably be changed to a simple subroutine which changes all linked styles to NORMAL, regardless of their name, but that's a little draconian for my taste.

    Also, towards the end of the MAIN routine, there's a call to a form (frmUnusedStyles) which simply displays the array of all unused styles in a List Box, purely for the user's information. They can cancel the command at that point if they wish if they see anything funky.

    Anyway, my work here is done... have a happy Thanksgiving, all!
    Attached Files Attached Files
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

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
  •