Excel 2010 - 错误:无法使用.onAction运行宏SelectCell [英] Excel 2010 - Error: Cannot run the macro SelectCell using .onAction

本文介绍了Excel 2010 - 错误:无法使用.onAction运行宏SelectCell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!



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.


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 & """'"


I created a sub-procedure for SelectCell to display the values being sent as a debug. Same error.


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)
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屋!

登录 关闭
发送“验证码”获取 | 15天全站免登陆