Anda di halaman 1dari 4

'Declare mouse events

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)
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Public Const MOUSEEVENTF_RIGHTDOWN As Long = &H8
Public Const MOUSEEVENTF_RIGHTUP As Long = &H10
'Declare sleep
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare PtrSafe Function apiGetClassName Lib "user32" Alias _
"GetClassNameA" (ByVal Hwnd As Long, _
ByVal lpClassname As String, _
ByVal nMaxCount As Long) As Long
Private Declare PtrSafe Function apiGetDesktopWindow Lib "user32" Alias _
"GetDesktopWindow" () As Long
Private Declare PtrSafe Function apiGetWindow Lib "user32" Alias _
"GetWindow" (ByVal Hwnd As Long, _
ByVal wCmd As Long) As Long
Private Declare PtrSafe Function apiGetWindowLong Lib "user32" Alias _
"GetWindowLongA" (ByVal Hwnd As Long, ByVal _
nIndex As Long) As Long
Private Declare PtrSafe Function apiGetWindowText Lib "user32" Alias _
"GetWindowTextA" (ByVal Hwnd As Long, ByVal _
lpString As String, ByVal aint As Long) As Long
Private Const mcGWCHILD = 5
Private Const mcGWHWNDNEXT = 2
Private Const mcGWLSTYLE = (-16)
Private Const mcWSVISIBLE = &H10000000
Private Const mconMAXLEN = 255
Public Function FindWindow(Window_Name As String) As Integer
Sleep 200
FindWindow = 0
Dim xStr As String
Dim xStrLen As Long
Dim xHandle As Long
Dim xHandleStr, WND As String
Dim xHandleLen As Long, xHandleStyle As Long
On Error Resume Next
WND = Window_Name

xHandle = apiGetWindow(apiGetDesktopWindow(), mcGWCHILD)


Do While xHandle <> 0
xStr = String$(mconMAXLEN - 1, 0)
xStrLen = apiGetWindowText(xHandle, xStr, mconMAXLEN)
If xStrLen > 0 Then
xStr = Left$(xStr, xStrLen)
xHandleStyle = apiGetWindowLong(xHandle, mcGWLSTYLE)
If xHandleStyle And mcWSVISIBLE Then
If xStr = Window_Name Then
FindWindow = 1
End If

End If
End If
xHandle = apiGetWindow(xHandle, mcGWHWNDNEXT)
Loop
End Function
Public Function Cursor_move(x As Integer, y As Integer)
SetCursorPos x, y
Sleep 50
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
Sleep 500
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Application.Wait (Now + TimeValue("0:00:01"))
End Function
Public Function Press_Find()

Call Cursor_move(500, 500) ' press find Box text


SendKeys "^{A}" ' paste tag value in find box
Sleep 100
SendKeys "^{V}"
Sleep 50
Call Cursor_move(650, 500) ' Press OK in Find Box
Sleep 200
Call Cursor_move(650, 560) ' Press Cancel in Find Box
End Function
Public Function Add_Template()
Dim obj As New DataObject
obj.SetText ActiveCell.Offset(0, 8).Value
obj.PutInClipboard
Set WshShell = CreateObject("WScript.Shell")
Call Cursor_move(200, 162)

' SendKeys " " ' right Click and select all
' Sleep 50
' mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0
' Sleep 50
' mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
' Call Cursor_move(500, 310)
Sleep 50
SendKeys "^{V}"
Sleep 50
Call Cursor_move(435, 425) ' press adding Arrow
Sleep 100
Call Cursor_move(900, 50)
Sleep 100
Call Cursor_move(900, 80)
Application.Wait (Now + TimeValue("0:00:01"))

End Function

Public Function EnterTAG()


Call Cursor_move(200, 183) ' select TAG place in CM
Sleep 50
SendKeys " "
Sleep 50
mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0
Sleep 50
mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
Call Cursor_move(250, 310)
Sleep 50
SendKeys "^{V}"
Application.Wait (Now + TimeValue("0:00:01"))
End Function

Sub Assign_ITRS()

Dim i, j As Integer
Dim obj As New DataObject
Range("A1").FormulaR1C1 = "=SUBTOTAL(3,R4C2:R99149C2)"
Dim Templet, tag, tagwithTemp As String
Templet = ""
j = Range("A1").Value
Range("B3").Select
Templet = "MENA"
tag = "MENA"

For i = 1 To j

ActiveCell.Offset(1, 0).Select ' copy tag


Do Until ActiveCell.EntireRow.Hidden = False
ActiveCell.Offset(1, 0).Select
Loop
'
' If ActiveCell.Offset(0, 8).Text <> Templete Then
' Change_Template
' Templete = ActiveCell.Offset(0, 8).Text
' Else
' End If

If CapsLock = True Then Exit Sub

obj.SetText Selection.Text
obj.PutInClipboard

tag = Selection.Text
Call EnterTAG
tagwithTemp = "Assign Template for " & tag & " - \\Remote"

Call Cursor_move(630, 60) ' Press Find

If FindWindow("No Records For Searching - \\Remote") = 1 Then


Call Cursor_move(1030, 600) ' No Records For Searching Window
Call Cursor_move(1030, 600) ' Press OK ON Not Found Window
Call Cursor_move(650, 560) ' Press Cancel in Find Box
ActiveCell.Offset(0, 10).Value = "NOT Found"
GoTo NextIteration
Else:

Call Cursor_move(650, 560) ' Press Cancel in Find Box


End If

Call Cursor_move(900, 200) ' Press set templete Button


Application.Wait (Now + TimeValue("0:00:02"))

If FindWindow(tagwithTemp) = 1 Then
Add_Template
ActiveCell.Offset(0, 10).Value = "Assigned"
Else
ActiveCell.Offset(0, 10).Value = "Error"
Exit Sub
GoTo NextIteration
End If

NextIteration:
Next i

'MsgBox j & " ITRs Done"

End Sub

Sub testmouselocation()
' Call Cursor_move(435, 425) ' select TAG place in CM

SetCursorPos 900, 80

End Sub

Anda mungkin juga menyukai