我无法点击代码中提到的坐标,如下所示。光标只是悬停在坐标上而不是单击。
我怎样才能收到点击通知?
'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 Sub SingleClick()
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End Sub
Public Sub CreateAWorkbook()
Dim Asset_Id As String
Dim Current_Mark As String
Dim DateTimeStamp As String, WorkbookName As String
SetCursorPos 481, 38
SingleClick
SetCursorPos 336, 69
SingleClick
Asset_Id = Range("F2").Value
Current_Mark = Range("I2").Value
If IsEmpty(Range("F2").Value) = False And IsEmpty(Range("I2").Value) = False Then
MessageToDisplay = "The Asset id is : " & Asset_Id & " and current mark is: " & Current_Mark
MsgBox (MessageToDisplay)
Else
MessageToDisplay = "The Asset id is not present"
MsgBox (MessageToDisplay)
End If
End Sub