vba 创建消息框,当单元格被选中时(excel)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26847478/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 05:11:35  来源:igfitidea点击:

Create Message box, when cell is selected (excel)

excelvba

提问by KoenR.

Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.Address = "$B" Then
       MsgBox "Something"
   End If
End Sub

Hello, I have a problem with a macro, I want to create a pop-up message when somebody clicks on B1. This Macro for some reason does'nt do anything, it's probably something simple/stupid, anybody has any idea's?

你好,我的宏有问题,我想在有人点击 B1 时创建一个弹出消息。由于某种原因,这个宏没有做任何事情,这可能是简单/愚蠢的事情,有人有任何想法吗?

回答by Gareth

You're using the wrong Worksheet event. You need to use the Worksheet_SelectionChangeevent like so:

您使用了错误的 Worksheet 事件。您需要Worksheet_SelectionChange像这样使用该事件:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    If Target.Address = "$B" Then
        MsgBox "Something"
    End If

End Sub

Make sure you place this in the sheets module that you wish it to fire from.

确保将其放置在您希望它从中触发的工作表模块中。