工作表选择更改未触发 [英] Worksheet Selection Change is not firing
问题描述
- Worksheet_SelectionChange
- Button1_Click
- MyMacro
当我点击工作表中的按钮时,Button1会触发。从Button1_Click调用时,MyMacro会触发。当我更改单元格或更改工作表时,我的Worksheet_SelectionChange方法不会触发。我想要一个在退出单元格时触发的方法。我从网上试过各种样品。他们在他们的示例中都有一个Worksheet_SelectionChange方法。当我离开单元格时,我需要做什么来触发方法?这是我的代码:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.EnableEvents = True
MsgBoxTEST
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)
工作表(942)。Range(J+ CStr BR))Value = FileName
MyMacro
End Sub
私有子MyMacro()
MsgBox我刚离开A2,0,
End Sub
你会有将 Worksheet_SelectionChange
sub移动到工作表(模块)。只需右键单击该选项卡,然后选择查看代码即可。
这是因为 Worksheet_SelectionChange
可以为每张纸不同。通过将其放在特定的表格上,Excel知道什么时候应该触发。
I have an Excel Macro enabled file. I have 3 methods / functions in my Module1.
- Worksheet_SelectionChange
- Button1_Click
- MyMacro
Button1 fires when I click on my button in the worksheet. MyMacro fires when called from the Button1_Click. My Worksheet_SelectionChange method does not fire when I change cells or when I change worksheets. I would like a method that fires when I exit a cell. I jave tried various samples from the web. They all have a Worksheet_SelectionChange method in their samples. What do I have to do to trigger a method when I leave a cell? Here is my code:
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
You'll have to move the Worksheet_SelectionChange
sub to the worksheet (module). Just right-click on the tab and select View Code this is where it should be.
That's because the Worksheet_SelectionChange
can be different for each sheet. By placing it on a particular sheet Excel knows when the even should fire.
这篇关于工作表选择更改未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!