How do I determine if an entire cell is selected vs...

  • Thread starter David Cardinale
  • Start date
D

David Cardinale

Hello,

I am trying to figure out how I can programatically determine if an entire
cell has been selected (by the user clicking on the border around the cell)
as opposed to simply having the cursor in the cell. I've tried everything I
can think of with Word.Selection but can't find any differences.

My problem is that I am inserting bookmarks into the cell, but whenever the
entire cell is selected, Word's formatting character for the cell ends up
within the bookmark and I need to prevent this.

Thank you.

David
 
R

RichN

Hi David,

I don't know if this will help - I don't really know Visual Basic - but I do
know that there are different ways to "access" a cell. You can click into
the cell - between characters. You can also use the arrow to select the
cell. Or you can use the right arrow key to move from the last character in
a cell to the first character in the next cell. Maybe using the arrow key is
what you want?

Rich
 
S

Shauna Kelly

Hi David

If you turn on non-printing characters (see
http://www.word.mvps.org/FAQs/Formatting/NonPrintChars.htm), you'll see that
every cell is marked with an end-of-cell marker. If the user has the whole
cell selected, then the selection will include that end-of-cell marker. But
if the user has only selected some text (perhaps even all the text, but not
the cell itself), then the selection will not include the end-of-cell
marker.

The end-of-cell marker is actually 2 characters: chr(13) & chr(7), and you
can test for those in your code.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
T

Tony Jollans

Something like this should cover all the possibilities:

If Selection.Information(wdWithInTable) Then
If Selection.Cells.Count > 1 Then
MsgBox "Selection spans more than one Cell"
Else
If Selection.Range = Selection.Cells(1).Range Then
MsgBox "Whole Cell selected"
Else
MsgBox "Partial Cell selected"
End If
End If
Else
MsgBox "Selection not in a Table"
End If
 
D

David Cardinale

This is exactly what I needed. Thank You!

Tony Jollans said:
Something like this should cover all the possibilities:

If Selection.Information(wdWithInTable) Then
If Selection.Cells.Count > 1 Then
MsgBox "Selection spans more than one Cell"
Else
If Selection.Range = Selection.Cells(1).Range Then
MsgBox "Whole Cell selected"
Else
MsgBox "Partial Cell selected"
End If
End If
Else
MsgBox "Selection not in a Table"
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top