MOVE MOUSE POINTER

A

Alok

hi all
Could you please tell me how can i move the mouse cursur(pointer) throgh the
MSWORD 2003 macro VBA .

An early reponse will be much appreciated.

thankz
Alok
 
J

Jean-Guy Marcil

Alok was telling us:
Alok nous racontait que :
hi all
Could you please tell me how can i move the mouse cursur(pointer)
throgh the MSWORD 2003 macro VBA .

An early reponse will be much appreciated.

The short answer is that you can't.

What are you trying to do? There must be an easier way than trying to
control the mouse pointer.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
U

Ulf Nilsson

Hi,
Someone gave me this code. Hope it is useful:
*************************
'please search for info on mouse_event on the internet.

Declare Sub Sleep Lib "KERNEL32" (ByVal dwMilliseconds As
Long)
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_MOVE = &H1
Public Const MOUSEEVENTF_ABSOLUTE = &H8000
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4

Sub amove()
Dim i As Integer
Dim y_abs As Integer
System.Cursor = wdCursorNormal
'For i = 7000 To 2500 Step -170
For i = 30000 To 2500 Step -200
y_abs = i
' mouse_event MOUSEEVENTF_ABSOLUTE + MOUSEEVENTF_MOVE,
3000, y_abs, 0, 0
mouse_event MOUSEEVENTF_ABSOLUTE + MOUSEEVENTF_MOVE,
22000, y_abs, 0, 0
Sleep (2)
Next

mouse_event MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP, 0,
0, 0, 0
DoEvents 'so that opening the menu is shown now

For i = 1 To 40
mouse_event MOUSEEVENTF_MOVE, 0, 1, 0, 0
' Sleep (50)
Sleep (2)
Next

'to the right
For i = 1 To 30
mouse_event MOUSEEVENTF_MOVE, 1, 0, 0, 0
Sleep (2)
Next
End Sub

***************

/ Ulf
 
J

Jean-Guy Marcil

Ulf Nilsson was telling us:
Ulf Nilsson nous racontait que :
Hi,
Someone gave me this code. Hope it is useful:
*************************
'please search for info on mouse_event on the internet.

Declare Sub Sleep Lib "KERNEL32" (ByVal dwMilliseconds As
Long)
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_MOVE = &H1
Public Const MOUSEEVENTF_ABSOLUTE = &H8000
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4

Sub amove()
Dim i As Integer
Dim y_abs As Integer
System.Cursor = wdCursorNormal
'For i = 7000 To 2500 Step -170
For i = 30000 To 2500 Step -200
y_abs = i
' mouse_event MOUSEEVENTF_ABSOLUTE + MOUSEEVENTF_MOVE,
3000, y_abs, 0, 0
mouse_event MOUSEEVENTF_ABSOLUTE + MOUSEEVENTF_MOVE,
22000, y_abs, 0, 0
Sleep (2)
Next

mouse_event MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP, 0,
0, 0, 0
DoEvents 'so that opening the menu is shown now

For i = 1 To 40
mouse_event MOUSEEVENTF_MOVE, 0, 1, 0, 0
' Sleep (50)
Sleep (2)
Next

'to the right
For i = 1 To 30
mouse_event MOUSEEVENTF_MOVE, 1, 0, 0, 0
Sleep (2)
Next
End Sub

***************

Very interesting code. Thank you.
I knew it could be done through API calls (but did not know how and did not
feel like Googling on this, see my comments below for my reasons.)

Nevertheless, I still wrote
"The short answer is that you can't."
because I think there are two factors that we have to take into
consideration that will complicate the code:
1) Screen resolution (I tried with 4 screen resolutions and got 4 different
results)
2) User interference (If the user touches the mouse will the macro runs, the
result will be unpredictable)


Is there an easy way around that?
If so, I'll have to change my answer to "Yes, you can!"

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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