Excel 2010 - Error: Cannot run the macro SelectCell using .onAction

后端 未结 2 710
星月不相逢
星月不相逢 2021-01-22 01:47

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 speci

2条回答
  •  悲哀的现实
    2021-01-22 02:11

    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
    

    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
    

提交回复
热议问题