Hi,
I am trying to use vba to control mouse movements and clicks on screen. As a starting point I want to just minimise Excel then minimise the application visible after Excel is minimised but the code I've got so far won't do this - it minimises Excel ok but then won't do a further minimise of the next visible application on screen. I have two chunks of code as follows:
And then I run this macro:
Any help much appreciated.
I am trying to use vba to control mouse movements and clicks on screen. As a starting point I want to just minimise Excel then minimise the application visible after Excel is minimised but the code I've got so far won't do this - it minimises Excel ok but then won't do a further minimise of the next visible application on screen. I have two chunks of code as follows:
VBA Code:
Option Explicit
#If VBA7 Then
Public Declare PtrSafe Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Public Declare PtrSafe Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As LongPtr)
#Else
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)
#End If
Const MOUSEEVENTF_LEFTDOWN = &H2
Const MOUSEEVENTF_LEFTUP = &H4
Const MOUSEEVENTF_RIGHTDOWN As Long = &H8
Const MOUSEEVENTF_RIGHTUP As Long = &H10
Dim TimerActive As Boolean
And then I run this macro:
Code:
SetCursorPos 1804, 11 'x and y position
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Application.Wait Now + TimeSerial(0, 0, 2)
SetCursorPos 1828, 6 'x and y position
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Any help much appreciated.