我有一个启用Excel宏的文件。我的Module1中有3个方法/函数。
当我点击工作表中的按钮时,Button1会触发。从Button1_Click调用MyMacro时会触发。当我更改单元格或更改工作表时,我的Worksheet_SelectionChange方法不会触发。我想要一个退出单元格时触发的方法。我jave尝试了网上的各种样本。它们的样本中都有一个Worksheet_SelectionChange方法。当我离开牢房时,我该怎么做才能触发一个方法?这是我的代码:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.EnableEvents = True
MsgBox "TEST"
End Sub
Sub Button1_Click()
BR = ActiveSheet.Buttons(Application.Caller).TopLeftCell.Row
COL = ActiveSheet.Buttons(Application.Caller).TopLeftCell.Column
Dim FileName As String
FileName = Worksheets("942").Range("A" + CStr(BR)).Value
FileName = FileName & "_"
Dim RandomNumber As Integer
RandomNumber = Int((999 - 100 + 1) * Rnd + 100)
Worksheets("942").Range("J" + CStr(BR)).Value = FileName
MyMacro
End Sub
Private Sub MyMacro()
MsgBox " I just left A2", 0, ""
End Sub