ThaiDieuAnh
Thành viên hoạt động



- Tham gia
- 8/8/16
- Bài viết
- 139
- Được thích
- 24
- Nghề nghiệp
- Xây dựng
Chèn thêm 1 module với code:Em có Form như file đính kèm. Em muốn sau khi Propeties ShowModal = False và di chuyển cell trên cột B thì giá trị trong Textbox1 sẽ thay đổi theo ô đó, mong các anh chị giúp đỡ, em xin cảm ơn!
Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
Function IsFormLoaded(ByVal frmCaption As String) As Boolean
IsFormLoaded = FindWindow("ThunderDFrame", frmCaption) > 0
End Function
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
If IsFormLoaded("UserForm1") Then
If Not Intersect(Range("B4:B" & [B65500].End(xlUp).Row), Target) Is Nothing Then
If Target.Count = 1 Then
If IsDate(Target.Value) Then
UserForm1.TextBox1 = Target.Value
Cancel = True
End If
End If
End If
End If
End Sub
Chèn thêm 1 module với code:
Sửa code sự kiện BeforeRightClick trong file thành:Mã:Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" _ (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr Function IsFormLoaded(ByVal frmCaption As String) As Boolean IsFormLoaded = FindWindow("ThunderDFrame", frmCaption) > 0 End Function
Mã:Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean) If IsFormLoaded("UserForm1") Then If Not Intersect(Range("B4:B" & [B65500].End(xlUp).Row), Target) Is Nothing Then If Target.Count = 1 Then If IsDate(Target.Value) Then UserForm1.TextBox1 = Target.Value Cancel = True End If End If End If End If End Sub
Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
Giờ mà vẫn còn có người xài 2007 sao ta?Chỗ này không được anh ạ, dù em đã bỏ PtrSafe, em dùng Officel 2007Mã:Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" _ (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Khi di chuyển trên cells thì Textbox không nhận giá trị của cell và sự kiện BeforeRightClick không chạy anh ạ!Giờ mà vẫn còn có người xài 2007 sao ta?
Thôi thì dùng cái cũ:
Mã:Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _ (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Bạn phải bấm showform trước chứKhi di chuyển trên cells thì Textbox không nhận giá trị của cell và sự kiện BeforeRightClick không chạy anh ạ!
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Range("B4:B" & [B65500].End(xlUp).Row), Target) Is Nothing Then
If Target.Count = 1 Then
If IsDate(Target.Value) = True Then
If IsFormLoaded("UserForm1") = False Then UserForm1.Show
UserForm1.TextBox1 = Target.Value
Cancel = True
End If
End If
End If
End Sub
Vâng, cảm ơn anh nhiều ạ, chúc anh sức khỏeAh! Hay là bạn muốn click phải chuột thì form tự show và điền giá trị?
Nếu là thế thì sửa code sự kiện thành vầy:
Mã:Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean) If Not Intersect(Range("B4:B" & [B65500].End(xlUp).Row), Target) Is Nothing Then If Target.Count = 1 Then If IsDate(Target.Value) = True Then If IsFormLoaded("UserForm1") = False Then UserForm1.Show UserForm1.TextBox1 = Target.Value Cancel = True End If End If End If End Sub