Excel 2010 - 错误:无法使用.onAction运行宏SelectCell [英] Excel 2010 - Error: Cannot run the macro SelectCell using .onAction
问题描述
我一直在网路上查找这个问题的解决方案,但是由于某种原因,我无法找到与使用.onAction直接相关的选项。
I have been looking all over the internet for a solution to this problem but for some reason I can never find anything directly related to using .onAction with selecting a specific cell.
我正在使用另一个问题的答案作为参考:
I am using an answer to another question as a reference:
- https://stackoverflow.com/a/18199035
在循环的部分通过形状,脚本将.onAction事件分配给每个形状。无论何时在Excel 2010中运行,我得到错误:
In the section where it is looping through shapes, the script assigns an .onAction event to each shape. Whenever this is run in Excel 2010 I get the error:
Cannot run the macro "SelectCell "Sheet 1","$C$10"".
The macro may not be available in this workbook or all macros may be disabled.
我是新的VBA脚本为excel,所以我不知道是否是格式,但我知道它与这一行有关。
I am new to VBA scripting for excel so I have no idea if it is the formatting, but I know it is related to this line.
.OnAction = "'SelectCell """ & ws.Name & """,""" & cll.Address & """'"
我为SelectCell创建了一个子过程,以显示作为调试。相同的错误。
I created a sub-procedure for SelectCell to display the values being sent as a debug. Same error.
我尝试使用excel允许所有宏并禁用所有宏,但它对该错误没有影响。
I tried having excel allow all macros and disable all macros but it had no effect on the error.
如果有任何人知道我在哪里出问题或任何资源,我可以用来进一步教育自己,这将是非常感谢。
If anyone has any idea of where I am going wrong or any resources I can use to further educate myself, it would be greatly appreciated.
推荐答案
这个(在一个常规模块中都包含)适用于我。
This (both subs in a regular module) works for me.
Sub SelectCell(sht As String, rng As String)
ThisWorkbook.Sheets(sht).Range(rng).Select
End Sub
Sub Assign()
ActiveSheet.Shapes(1).OnAction = "'SelectCell """ & _
Selection.Parent.Name & """, """ & _
Selection.Address() & """'"
End Sub
如果 SelectCell
在一个表单代码模块中,那么您需要包含表单代码名称:
If SelectCell
is in a sheet code module, then you need to include the sheet code name:
Sub Assign()
ActiveSheet.Shapes(1).OnAction = "'Sheet1.SelectCell """ & _
Selection.Parent.Name & """, """ & _
Selection.Address() & """'"
End Sub
这篇关于Excel 2010 - 错误:无法使用.onAction运行宏SelectCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!