rob88
05-09-2013, 01:31 AM
Hi, i have a table containing the co-ordinates of different areas of a program that i want to be able to intereactive with from excell.
I am using SetCursorPos with click events to move the mouse to different areas and click - which all works fine in the sense that if i put in the line of code (for example)
Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Public Const MOUSEEVENTF_RIGHTDOWN As Long = &H8
Public Const MOUSEEVENTF_RIGHTUP As Long = &H10
SetCursorPos 200, 100 'x and y position
mouse_event &H2, 0, 0, 0, 0
mouse_event &H4, 0, 0, 0, 0
then the mouse is moved to 200, 100 and a click is initiated (which is fine)
my problem is i want to be able to to replace the 200, 100 with a cell value (in which i will have co ordinates)
for example
SetCursorPos range("A1").Value 'x and y position
mouse_event &H2, 0, 0, 0, 0
mouse_event &H4, 0, 0, 0, 0
where A1 = 200, 100
but if i try to run this i get 'compile error : argument not optional'
Anyone have any ideas? This must be possible as range("A1").Value = 200, 100 so
SetCursorPos range("A1").Value 'x and y position
is the same as
SetCursorPos 200,100 'x and y position
Thanks for any help :)
I am using SetCursorPos with click events to move the mouse to different areas and click - which all works fine in the sense that if i put in the line of code (for example)
Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Public Const MOUSEEVENTF_RIGHTDOWN As Long = &H8
Public Const MOUSEEVENTF_RIGHTUP As Long = &H10
SetCursorPos 200, 100 'x and y position
mouse_event &H2, 0, 0, 0, 0
mouse_event &H4, 0, 0, 0, 0
then the mouse is moved to 200, 100 and a click is initiated (which is fine)
my problem is i want to be able to to replace the 200, 100 with a cell value (in which i will have co ordinates)
for example
SetCursorPos range("A1").Value 'x and y position
mouse_event &H2, 0, 0, 0, 0
mouse_event &H4, 0, 0, 0, 0
where A1 = 200, 100
but if i try to run this i get 'compile error : argument not optional'
Anyone have any ideas? This must be possible as range("A1").Value = 200, 100 so
SetCursorPos range("A1").Value 'x and y position
is the same as
SetCursorPos 200,100 'x and y position
Thanks for any help :)