Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
owen owen is offline
external usenet poster
 
Posts: 61
Default 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   Report Post  
Posted to microsoft.public.word.docmanagement
Greg Maxey[_2_] Greg Maxey[_2_] is offline
external usenet poster
 
Posts: 668
Default 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   Report Post  
Posted to microsoft.public.word.docmanagement
owen owen is offline
external usenet poster
 
Posts: 61
Default 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   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default 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

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cursor location when open a new document John M Microsoft Word Help 1 February 2nd 09 03:52 PM
Cursor location BrettG Microsoft Word Help 1 November 12th 07 12:09 PM
How do I save the cursor location? Jim L. Microsoft Word Help 1 April 15th 05 07:32 PM
Template Cursor Location Raymond O'Neill Microsoft Word Help 1 March 3rd 05 07:32 PM
Cursor location? WandaC Page Layout 1 December 16th 04 07:14 PM


All times are GMT +1. The time now is 08:54 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"