Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Paragraph without a style (2002)

    Has anyone ever encountered a paragraph that had no style applied before? I was troubleshooting a co-worker's document that was tripping up on one of my macros, and I traced the problem to a line that was testing the paragraph style type, as in:
    <pre>If para.Style.Type = wdStyleTypeCharacter Then</pre>

    The error was "Block or Object Variable not set"
    After scratching my head a bit, I went back to the document, and noticed that in the styles pulldown on the Formatting toolbar, there was nothing. Tried Ctrl-Q, and even Ctrl-Space, and still nothing.
    With the cursor in the offending paragraph, I went back to the VBA IDE, and in the immediate window, tried:
    <pre>?Selection.Range.Paragraphs.First.Style.Typ e</pre>

    And I got the same error message about an object variable not being set. <img src=/S/confused.gif border=0 alt=confused width=15 height=20>
    Re-applying the paragraph style resolved the problem, but it was such a strange thing that I wondered if anyone ever encountered that before, and if so, had any insight into why/when it happens.

  2. #2
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Paragraph without a style (2002)

    Hi Andrew,

    It's probably caused by an undocumented feature: You can hide styles in Word (ActiveDocument.Styles("XY").Hidden=True).

    In previous versions, I think you were able to just go into the paragraph and use "Selection.Style.Hidden=False". But it doesn't seem to work any more in Word2002/2003.

    If you save in HTML format and reopen, the style(s) should re-appear.

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus

  3. #3
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Paragraph without a style (2002)

    Very interesting, Klaus. Thank you.

    However, my problem only affected a single paragraph that used the style (it was the Normal style), and not the rest of the paragraphs that shared the style.

    When making a style hidden using the undocumented feature you described, all paragraphs using that style exhibit the same "missing style" behavior, and the style no long appears at all in the Style Area Width. Neither was the case with my coworker's document.

    Thank you for your insight.

  4. #4
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Paragraph without a style (2002)

    Hi Andrew,

    If it's possible, could you strip the document down a bit and post it here? Or mail it to me privately?
    I'd love to have a look at it.

    I had quite a few problems with my old Word97/2000 macros in Word2002/2003 because of the new list and table styles.
    A few times, I had to replace Range.Style or Selection.style with a loop through all styles, picking out the paragraph or character style.
    Which slows down already slow macros quite considerably <img src=/S/frown.gif border=0 alt=frown width=15 height=15>

    But I can't quite see how the list and table styles might cause the problem you see.

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus

Posting Permissions

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