Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Jun 2002
    Location
    Oxford, United Kingdom
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How can I detect if text is selected? (VBA/Word 97

    I'm writing a macro where I need to be able to detect whether a user has selected text. The macro will act differently depending on whether or not text has been selected. I tried testing

    if selection.active = True then...

    but that didn't work. How can I do this in VBA/Word?

    Thanks,
    Grant

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: How can I detect if text is selected? (VBA/Word 97

    <pre>Select Case Selection.Type
    Case wdSelectionNormal

    End Select
    </pre>

    StuartR

  3. #3
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How can I detect if text is selected? (VBA/Word 97

    Aside from Stuart's answer, you may try selection.text

    For instance
    <pre>if len (trim(selection.text)) >1 then</pre>

    will tell you if any non-space text has been selected
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  4. #4
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How can I detect if text is selected? (VBA/Word 97

    THe best way, IMHO, is to test the Start and End properties of the Selection.

    Len(Selection.Text) won't do because that darn pilcrow that MSFT (ab)uses as a paragraph mark.

    I've never liked the IP test because, as I recall, there was some situations I found in WordBasic that didn't work as expected.

    Testing Start and End proprties has not failed me yet. Ouch, I likely just jubxed meself!.

  5. #5
    New Lounger
    Join Date
    Jun 2002
    Location
    Oxford, United Kingdom
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How can I detect if text is selected? (VBA/W

    Thanks to all for very helpful code.

    Grant

Posting Permissions

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