VBA to control the Mouse

D

DejaVu

Is there anyway to control the mouse movements, position, and clicks? I
need to control the mouse to click a certain area on my database screen.
I can't get the control with the keyboard, and the mouse is the only
other option.

TIA,

DejaVu
 
T

Tom Ogilvy

Unless you are programming some type of instructional routine that guides
the user to perform an action, you are headed in the wrong direction. If
you need to execute the click event for a commandbutton in Sheet1 (Sheet1
being the code name) for example, you would rename the click event to public

Private Sub CommandButton1_Click()

becomes

Public Sub CommandButton1_Click()

then you could do

Sheet1!CommandButton1_Click()

to execute the click event.

easier is move the meat of the code to a general module a a public sub and
then you can call that from either the click event or your own routine

Private Sub CommandButton1_Click()
MyCode
End Sub

in a general module

Public Sub Mycode()
' code that used to be in the click event
End Sub
 
D

DejaVu

Thanks for the reply Tom.

I'm still not sure how to handle this though... I don't want to click
anywhere on a worksheet (or even in excel for that matter). I need to
mouse click on another program. Can I use VB code to control what the
mouse does, or can I use some sort of API call to (1) Open the program
window and (2) make the mouse click on a specified pixel or "latitude"
& "longitude" on my screen? I thought I read something that it was
possible to input the coordinates and have the mouse move there and
click on command... am I way off??

Thanks,

DejaVu
 
T

Tom Ogilvy

I have no idea if you can do that - but if you can, I would say the approach
definitely isn't a route heavily travelled.
 

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