Thủ tục gọi Form? (1 người xem)

Liên hệ QC

Người dùng đang xem chủ đề này

matran25251325

Thành viên tiêu biểu
Tham gia
13/1/11
Bài viết
424
Được thích
39
Option Explicit
Private Sub CommandButton1_Click()
UserForm1.Show
End Sub
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Range("A8:A65536"), Target) Is Nothing Then
UserForm1.Show: Cancel = True
End If
End Sub

Các anh cho em hỏi theo code trên thì thủ tục click chuột trái 2 lần thì sẽ gọi form, Vậy nếu giờ em muốn khi nhấp Enter thì sẽ gọi form. Vậy em phải thay đổi chỗ BeforeDoubleClick bằng gì?
 
Option Explicit
Private Sub CommandButton1_Click()
UserForm1.Show
End Sub
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Range("A8:A65536"), Target) Is Nothing Then
UserForm1.Show: Cancel = True
End If
End Sub

Các anh cho em hỏi theo code trên thì thủ tục click chuột trái 2 lần thì sẽ gọi form, Vậy nếu giờ em muốn khi nhấp Enter thì sẽ gọi form. Vậy em phải thay đổi chỗ BeforeDoubleClick bằng gì?
Trên sheet hình như không có bắt sự kiện KeyDown, KeyPress...
 
Upvote 0
Option Explicit
Private Sub CommandButton1_Click()
UserForm1.Show
End Sub
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Range("A8:A65536"), Target) Is Nothing Then
UserForm1.Show: Cancel = True
End If
End Sub

Các anh cho em hỏi theo code trên thì thủ tục click chuột trái 2 lần thì sẽ gọi form, Vậy nếu giờ em muốn khi nhấp Enter thì sẽ gọi form. Vậy em phải thay đổi chỗ BeforeDoubleClick bằng gì?
Bạn tham khảo bài này nhé.
 
Upvote 0
Option Explicit
Private Sub CommandButton1_Click()
UserForm1.Show
End Sub
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Range("A8:A65536"), Target) Is Nothing Then
UserForm1.Show: Cancel = True
End If
End Sub

Các anh cho em hỏi theo code trên thì thủ tục click chuột trái 2 lần thì sẽ gọi form, Vậy nếu giờ em muốn khi nhấp Enter thì sẽ gọi form. Vậy em phải thay đổi chỗ BeforeDoubleClick bằng gì?

Yêu cầu này có thể dùng application.onkey, nhưng phím Enter là phím chính mà đem làm như thế có lẽ sẽ phát sinh đủ thứ đó.
 
Upvote 0
Dạ Enter chỉ trên cột A thôi anh. Anh QuangHai có thể giúp em đc không ạ? Xem bài của bác NghiãPhuc e còn mù mờ quá
 
Upvote 0
Dạ Enter chỉ trên cột A thôi anh. Anh QuangHai có thể giúp em đc không ạ? Xem bài của bác NghiãPhuc e còn mù mờ quá
Copy code này vào 1 module rồi test thử xem thế nào. Nhớ lưu file, đóng file rồi mở ra lại code mới hoạt động
PHP:
Sub moform()
If ActiveCell.Column = 1 Then UserForm1.Show False
End Sub
Sub auto_open()
    Application.OnKey "~", "moform"
    Application.OnKey "{Enter}", "moform"
End Sub

Hoặc là bỏ code này vào sheet

PHP:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.OnKey "~", "moform"
Application.OnKey "{Enter}", "moform"
End Sub
 
Lần chỉnh sửa cuối:
Upvote 0

Bài viết mới nhất

Back
Top Bottom