Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
If Statement (For Cursor Location)
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 |
#2
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
If Statement (For Cursor Location)
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 -- Greg Maxey - Word MVP My web site http://gregmaxey.mvps.org Word MVP web site http://word.mvps.org "Owen" wrote in message ... 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 |
#3
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
If Statement (For Cursor Location)
Greg
That worked first time. Thanks very much for your help. Regards Owen "Greg Maxey" wrote: 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 -- Greg Maxey - Word MVP My web site http://gregmaxey.mvps.org Word MVP web site http://word.mvps.org "Owen" wrote in message ... 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 |
#4
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
If Statement (For Cursor Location)
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 Word MVP web site http://word.mvps.org Owen wrote: 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 |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Cursor location when open a new document | Microsoft Word Help | |||
Cursor location | Microsoft Word Help | |||
How do I save the cursor location? | Microsoft Word Help | |||
Template Cursor Location | Microsoft Word Help | |||
Cursor location? | Page Layout |