BeforeDoubleClick 宏触发器在 excel 2010 VBA 中不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18080526/
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
BeforeDoubleClick macro trigger not working in excel 2010 VBA
提问by Adam.Butler
I am trying to trigger a macro in excel 2010 using the BeforeDoubleClick
procedure. However, it does not appear to be working. I have searched extensively to see if other people have been having the same problems, a couple have but I have tried their solutions and it either wasn't applicable or didn't work. The code is very simple as I have stripped it back in order to test it.Is there something foolishly wrong with my code? (I am a Stack and VB noob so please be patient)
我正在尝试使用该BeforeDoubleClick
过程在 excel 2010 中触发宏。但是,它似乎不起作用。我进行了广泛的搜索,看看其他人是否也遇到过同样的问题,有几个人遇到过,但我已经尝试过他们的解决方案,但它要么不适用,要么不起作用。代码很简单,为了测试我已经把它剥离了。我的代码有什么愚蠢的错误吗?(我是 Stack 和 VB 菜鸟,请耐心等待)
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Value = "GO" Then Cancel = True
MsgBox ("done")
End Sub
I have tried setting it to public sub, putting "Application.EnableEvents = True" in the immediate window. Workbook is set to enable all macros. No add ins are running. I have been through the XLSTART folder and its all empty. Even created a digital signature at one point as someone suggested it. Could it still be some from of compatibility issue with previous versions of excel?
我尝试将其设置为公共子,将“Application.EnableEvents = True”放在即时窗口中。工作簿设置为启用所有宏。没有加载项正在运行。我已经浏览过 XLSTART 文件夹,它全是空的。甚至在某个时候创建了一个数字签名,正如有人建议的那样。它是否仍然是与以前版本的excel的兼容性问题?
Also when you do double click in the work sheet even though cancel = True the cell just opens up for editing as normal.
此外,当您在工作表中双击时,即使取消 = True 单元格也会正常打开进行编辑。
Please Help
请帮忙
回答by MikeD
The code you posted, when entered in a sheet's local module (e.g. Sheet1) will work without flaws. From the point of user experience you hardly notice any difference, namely
您发布的代码在输入到工作表的本地模块(例如 Sheet1)中时将正常工作。从用户体验的角度来看,您几乎没有注意到任何区别,即
if you double click a cell with value "GO", you see the [Done] msgbox, and after quitting this you are left with the cell selected but not in edit mode (i.e. insert cursor not in cell)
if you click a cell with any other value (e.g. "abc", or even an empty cell), you see the [Done] msgbox, and after quitting this you are in cell edit mode with the write cursor placed after the last letter of the current value, so you can immediately start typing into the cell.
如果你双击一个值为“GO”的单元格,你会看到 [Done] msgbox,退出后你会留下选中的单元格但不处于编辑模式(即插入光标不在单元格中)
如果您单击具有任何其他值的单元格(例如“abc”,甚至是空单元格),您会看到 [Done] msgbox,退出后您将处于单元格编辑模式,写入光标位于当前值,因此您可以立即开始在单元格中输入。
Having said that, even in 1. above nothing prevents you to start typing. By press of the first letter your "GO" is entirely replaced by the single letter you typed - so the difference for the user is minimal and could well be overlooked, unless your final code does a bit more like repositioning the selection, coloring the cell etc.
话虽如此,即使在 1. 上面也没有什么能阻止你开始打字。通过按下第一个字母,您的“GO”将完全被您输入的单个字母替换 - 因此用户的差异很小并且很可能被忽略,除非您的最终代码更像是重新定位选择,为单元格着色等等。