If Statement (For Cursor Location)

O

Owen

I am having trouble working out the code to test the current cursor location
against an IF statement.

For example, i am trying to code the following:

"IF the cursor location is located in Table(6) , Column(2) of the active
document, THEN.....ELSE.....".

I am ok with the coding of my THEN/ELSE statements, its the IF statement i
need help with.

I have tried the statement below which is not working:

if selection.tables(6).columns(2)=true, then....

Would be grateful if anyone can show me why i am going wrong.

Thanks
 
G

Greg Maxey

Owen,

The problem as I understand it is that a table column is not a range object.
One way of doing this is to select the column and then test to see if the IP
is in the selection. Something like this might work:

Sub ScratchMacro()
Dim oRng As Word.Range
Set oRng = Selection.Range
ActiveDocument.Tables(6).Columns(2).Select
If oRng.InRange(Selection.Range) Then
MsgBox "Bingo"
Else
MsgBox "Not here"
End If
oRng.Select
End Sub
 
G

Graham Mayor

One possibility would be

For i = 1 To ActiveDocument.Tables.Count
If Selection.Information(wdWithInTable) And i = 6 Then
If Selection.Information(wdStartOfRangeColumnNumber) = 2 Then
'Cursor is in column 2 of Table 6
End If
End If
Next i

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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