This is an example to control mouse to click on the specify position by using Windows API function. First, declare the following in the code
Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Private 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)
Private Declare Function GetCursorPos Lib "user32" (lpPoint As pointapi) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Const MOUSEEVENTF_LEFTDOWN As Integer = 2
Const MOUSEEVENTF_LEFTUP As Integer = 4
Const MOUSEEVENTF_RIGHTDOWN As Integer = 8
Const MOUSEEVENTF_RIGHTUP As Integer = 16
Private Type pointapi
X As Long
Y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
------------------------------------------------------------------
Here is an example
Sub test()
SetCursorPos 200, 200 'set mouse position at 200, 200
Call mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0) 'click left mouse
Call mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0) 'release left mouse
End Sub
Showing posts with label Example. Show all posts
Showing posts with label Example. Show all posts
Wednesday, February 22, 2012
Monday, February 13, 2012
List files in specific path
Sub FileList()
'*** List all files in specific path and pattern ***'
'*** in Excel file start from cell A1 of sheet1 ***'
'*** using GetFileList and IsArray function ***'
Dim p As String
Dim X As Variant
p = "C:\test\*.xls" 'select only *.xls pattern
X = GetFileList(p)
Select Case IsArray(X)
Case True 'files found
'MsgBox UBound(x)
Sheets("Sheet1").Range("A:A").Clear
For i = LBound(X) To UBound(X)
Sheets("Sheet1").Cells(i, 1).Value = X(i)
Next i
Case False 'no files found
MsgBox "No matching files"
End Select
End Sub
'*** List all files in specific path and pattern ***'
'*** in Excel file start from cell A1 of sheet1 ***'
'*** using GetFileList and IsArray function ***'
Dim p As String
Dim X As Variant
p = "C:\test\*.xls" 'select only *.xls pattern
X = GetFileList(p)
Select Case IsArray(X)
Case True 'files found
'MsgBox UBound(x)
Sheets("Sheet1").Range("A:A").Clear
For i = LBound(X) To UBound(X)
Sheets("Sheet1").Cells(i, 1).Value = X(i)
Next i
Case False 'no files found
MsgBox "No matching files"
End Select
End Sub
Subscribe to:
Posts (Atom)