Có anh chị nào sửa code em với ạ
module 1
#If VBA7 And Win64 Then
'64bit
Declare PtrSafe Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long
Declare PtrSafe Function setcursorpos Lib "user32" Alias "SetCursorPos" (ByVal x As Long, ByVal y As Long) As Long
#Else
'32 bit
Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long
Declare Function setcursorpos Lib "user32" Alias "SetCursorPos" (ByVal x As Long, ByVal y As Long) As Long
#End If
Type PointAPI
X_Pos As Long
Y_Pos As Long
End Type
Sub DATTOADO()
Dim Hold As PointAPI
Sheet1.Range("B3:C4").Clear
Application.Wait Now + TimeSerial(0, 0, 5)
GetCursorPos Hold
Sheet1.Range("B3").Value = Hold.X_Pos
Sheet1.Range("C3").Value = Hold.Y_Pos
Application.Wait Now + TimeSerial(0, 0, 5)
GetCursorPos Hold
Sheet1.Range("B4").Value = Hold.X_Pos
Sheet1.Range("C4").Value = Hold.Y_Pos
End Sub
--------------
Code Module 2
#If VBA7 And Win64 Then
'64bit
Public Declare PtrSafe Function setCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As LongPtr
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 Long)
#Else
'32 bit
Public Declare Function setcursorpos Lib "user32" Alias "SetCursorPos" (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
Public Const mouseeventf_leftdown As Long = &H2
Public Const mouseeventf_leftup As Long = &H4
Public Const mouseeventF_Rightdown As Long = &H8
Public Const mouseeventF_rightup As Long = &H10
'Declare sleep
Declare Sub sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
Sub Chaytudong()
Dim i As Long, j As Long
j = Sheet1.Range("E" & Rows.Count).End(xlUp).Row 'tim dong cuoi so dt
For i = 2 To j
If Sheet1.Range("A1") <> "" Then
Exit Sub
End If
If Sheet1.Range("A" & i) <> "" Then
Sheet1.Range("E" & i).Copy
Sheet1.Range("F" & i).Value = "ok"
Application.Wait Now + TimeSerial(0, 0, 1)
setCursorPos Sheet1.Range("B3").Value, Sheet1.Range("C3").Value 'x and y position
Application.Wait Now + TimeSerial(0, 0, 1)
mouse_event mouseeventf_leftdown, 0, 0, 0, 0
mouse_event mouseeventf_leftup, 0, 0, 0, 0
mouse_event mouseeventf_leftdown, 0, 0, 0, 0
mouse_event mouseeventf_leftup, 0, 0, 0, 0
Application.Wait Now + TimeSerial(0, 0, 1)
Application.SendKeys ("~")
Application.Wait Now + TimeSerial(0, 0, 1)
Application.SendKeys ("^v")
Application.Wait Now + TimeSerial(0, 0, 1)
Application.SendKeys ("~")
Sheet1.Range("G1:G20").Copy
Application.Wait Now + TimeSerial(0, 0, 1)
setCursorPos Sheet1.Range("B4").Value, Sheet1.Range("C4").Value 'x and y position
Application.Wait Now + TimeSerial(0, 0, 1)
mouse_event mouseeventf_leftdown, 0, 0, 0, 0
mouse_event mouseeventf_leftup, 0, 0, 0, 0
Application.Wait Now + TimeSerial(0, 0, 1)
Application.SendKeys ("^v")
Application.Wait Now + TimeSerial(0, 0, 1)
Application.SendKeys ("~")
Application.SendKeys ("~")
End If
Next
End Sub