Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    UK
    Posts
    239
    Thanks
    4
    Thanked 1 Time in 1 Post

    Is cursor in a table cell? (Word XP)

    I need to write an If Then Else macro where the If part has to start by determining whether or not the cursor is in a table cell.

    I can write the two actions but I have not been able to figure out how to determine whether or not the cursor is in a table cell. Can someone please help me with that bit?

  2. #2
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Is cursor in a table cell? (Word XP)

    Not too sure on this, but I have this as a code snippet that (I presume) I have used in the past:

    ' Check if cursor is within a table cell

    If Selection.Information(wdWithInTable) Then
    ...
    Else
    ...
    End If

    Checking through the Word VBA help file gives more details on the possible arguments for the .Information property.

    Alan

  3. #3
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    UK
    Posts
    239
    Thanks
    4
    Thanked 1 Time in 1 Post

    Re: Is cursor in a table cell? (Word XP)

    Perfect. Many thanks.

  4. #4
    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: Is cursor in a table cell? (Word XP)

    There's a tiny risk that the insertion point will be at an end-of-row marker rather than inside a cell. If you need to be inside a cell, you'll want to check for this too:

    If Not Selection.Information(wdAtEndOfRowMarker) Then
    'do stuff that happens only inside a cell
    End If

  5. #5
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    UK
    Posts
    239
    Thanks
    4
    Thanked 1 Time in 1 Post

    Re: Is cursor in a table cell? (Word XP)

    Thanks for the additional information. I'll amend my code.

Posting Permissions

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