Archive of Mr Excel Message Board


Back to Excel VBA archive index
Back to archive home

How can I get current position of "cursor"?

Posted by P. P. Ervo on September 04, 2001 8:30 AM
How can I find the actual position of the cursor? I'am working with a macro that needs the actual position of the cursor.

Check out our Excel VBA Resources

Re: :-) How can I get current position of "cursor"?

Posted by Sean on September 04, 2001 2:58 PM

===========
Hi,

Enter a line

curloc = activecell.address

into your macro.

This will return the current cell value as "$A$3" if your cursor was in cell A3.

Hope this helps
Sean

========


Re: :-) How can I get current position of "cursor"?

Posted by Mark O'Brien on September 06, 2001 2:05 PM
If you need the actual cursor position and not the postion of the highlighted cell here's quick example of the GetCursorPos API call.

First, create a user form and add a commandbutton to it. Then add this code to the userform:

Private Type POINTAPI
x As Long
y As Long
End Type

Private Declare Function GetCursorPos Lib "user32" _
(lpPoint As POINTAPI) As Long

Dim pos As POINTAPI ' Declare variable


Private Sub CommandButton1_Click()
GetCursorPos pos ' Get Co-ordinates
MsgBox "Cursor Pointer is at:" & vbNewLine _
& "x:=" & pos.x & vbNewLine _
& "y:=" & pos.y
End Sub

Run the userform and when you click on the button you will be told where the cursor is.

Hope this is helpful.

========


This archive is from the original message board at www.MrExcel.com.
All contents © 1998-2004 MrExcel.com.
Visit our online store to buy searchable CD's with thousands of VBA and Excel answers.
Microsoft Excel is a registered trademark of the Microsoft Corporation.
MrExcel is a registered trademark of Tickling Keys, Inc.