vba Excel:触发双击事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12779021/
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
Excel: Trigger double click event
提问by Christer B
I have an Excel workbook that has been password protected by a third party. The interaction in that worksheet is done with double clicks to toggle check marks in fields. I would have to do 7000 double clicks to finish this task, so I would like to automate it. My suspicion is that the worksheet is using the BeforeDoubleClick event. The password encryption hides the actual implementation.
我有一个受第三方密码保护的 Excel 工作簿。该工作表中的交互是通过双击来切换字段中的复选标记来完成的。我必须双击 7000 次才能完成此任务,因此我想将其自动化。我怀疑工作表正在使用 BeforeDoubleClick 事件。密码加密隐藏了实际的实现。
I started out running a test in my own worksheet, without a password, to rule those issues.
我开始在我自己的工作表中运行测试,没有密码,以解决这些问题。
I have tried Application.DoubleClick:
我试过 Application.DoubleClick:
Range("B17").Select
Application.DoubleClick
But that doesn't trigger my event code (Worksheet_BeforeDoubleClick), which do work for "real" double clicks.
但这不会触发我的事件代码 (Worksheet_BeforeDoubleClick),它确实适用于“真正的”双击。
That is apparently by design according to MS: http://msdn.microsoft.com/en-us/library/office/aa220809(v=office.11).aspx
这显然是根据 MS 设计的:http: //msdn.microsoft.com/en-us/library/office/aa220809(v=office.11).aspx
The DoubleClick method doesn't cause this event to occur.
DoubleClick 方法不会导致此事件发生。
I can't call the third party event code directly, since the sub is private. Is there a way around this?
我不能直接调用第三方事件代码,因为 sub 是私有的。有没有解决的办法?
I have tried this both in Excel 2003 and 2007.
我在 Excel 2003 和 2007 中都尝试过这个。
采纳答案by Konstant
Here is workaround that you can try (I tried this on Excel 2007)
这是您可以尝试的解决方法(我在 Excel 2007 上尝试过)
- Make the
BeforeDoubleClick
event public (I used this in Sheet1)Public Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
In your macro simply call this function
Range("B17").Select Call Sheet1.Worksheet_BeforeDoubleClick(Selection, False)
- 令
BeforeDoubleClick
事件公开(我在Sheet1用这个)Public Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
在您的宏中只需调用此函数
Range("B17").Select Call Sheet1.Worksheet_BeforeDoubleClick(Selection, False)