Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Sep 2001
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Prob2: Displaying paragraph style (Eng/Word/97-2000)

    I need to display the style of the paragraph currently being edited in a dialog box. I am using the collowing code:
    lblCurrentStyle.Caption = ActiveDocument.Paragraphs.Style

    Here's the issue:
    When there is only one style used in the document it works just fine. As soon as there are more than one styles used, I get the following error message;
    Run-time error '91'":
    Object variable or With block variable not set

    Any help is greatly appreciated, because I had to go back to Wordbasic (shudder) to get the end result to work.

  2. #2
    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: Prob2: Displaying paragraph style (Eng/Word/97-2000)

    The problem is that this code -

    lblCurrentStyle.Caption = ActiveDocument.Paragraphs.Style

    - looks at the entire paragraph collection of the document as a whole. To drill down to the current paragraph requires knowing the nature of the Selection object at that moment:

    (1) Insertion point only or selection entirely inside a single paragraph: easy
    lblCurrentStyle.Caption = Selection.Paragraphs(1).Style

    (2) Selection starts in the right paragraph, but ends who-knows-where: same code as (1)

    (3) Selection starts who-knows-where and ends in the right paragraph
    lblCurrentStyle.Caption = Selection.Paragraphs(Selection.Paragraphs.Count).S tyle

    (4) Arbitrary selection: I give up at that point <img src=/S/wink.gif border=0 alt=wink width=15 height=15>

    If you have a range object defined and you are addressing the paragraph that way, it is the same idea, but I haven't tested how to code it.

  3. #3
    New Lounger
    Join Date
    Sep 2001
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Prob2: Displaying paragraph style (Eng/Word/97-2000)

    Well - suggestion number one was EXACTLY what I was looking for. I was unaware that Paragraphs could be part of the Selection object. You just made my coding extremely smaller, as I'm sure you probably know that the Wordbasic equivalents are bulky.

    thanks much!

Posting Permissions

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