PDA

View Full Version : Sleeper: Using VBA to move the mouse to a specific coordinate and left click?



Wikkles
06-22-2010, 08:44 AM
Hi everyone, I'm new here and relatively new to VBA coding but I was wondering if this is possible to do with VBA.

I have two workbooks that I use at work, one private: book2.xlsm and one public:book1.xlsm. I've written some code in the public book to help control the flow of things. What I'm basically trying to do is get VBA to (while book2 is the active window) move the mouse to a specific coordinate and left click on a button, then return to it's original position after the button is clicked.

Here's the code I'm working with (please excuse the sloppyness)

Sub PhoneyWork()
' PhoneyWork Macro
' Keyboard Shortcut: Ctrl+e
Range("A2:E2").Select
Selection.Copy
Sheets("Sheet2").Select
ActiveSheet.Paste
Rows("1:1").Select
Application.CutCopyMode = False
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A1").Select
Sheets("Sheet1").Select
Range("A2").Select
Selection.Copy
Windows("Book2.xlsm").Activate
Range("A3").Select
ActiveSheet.Paste
'-------------------
'Here is where I'd like to insert the mouse command
'-------------------
Windows("Book1.xlsm").Activate
Range("E2").Select
Application.CutCopyMode = False
Selection.ClearContents
Range("A2").Select
Selection.ClearContents
Windows("Book2.xlsm").Activate
End Sub
Any help would be appreciated! Thanks

mdmackillop
06-22-2010, 10:42 AM
Welcome to VBAX
While this may be possible, it is not trivial. I can't think what would specifically require this action. Can you explain further or attach a sample workbook to demonstrate what you are trying to achieve. (Manage Attachments in Go Advanced reply section)

Wikkles
06-22-2010, 08:21 PM
Attached is a modified example of what I'm trying to do. The first two sheets "Input Sheet" and "Log Sheet" are in a separate workbook than the "Fake Protected Workbook" sheet.

Essentially I'm wanting to get Excel to move the mouse and click the "Open Worksheet" button in the "F P W" sheet after it pastes the Lab # into "F P W" and before it switches back to the "Input Sheet"

Basically I'm just trying to save myself and the others in my department who use this same log file a couple hundred mouse clicks a day.

Any help would be greatly appreciated.
Thanks again.

shrivallabha
06-22-2010, 10:28 PM
Instead you can put your code under the specific worksheet as by choosing the "Input Sheet" in the VBE Explorer:


Sub Worksheet_Calculate()
Windows("Book1.xlsm").Activate
End Sub