E
ExcelMonkey
I am trying to get this code to work in Excel 2007 as per
http://www.mrexcel.com/forum/showthread.php?t=80626
I have placed it in Thisworkbook module. It is failing on the line:
Set CtrlCbcRet = CommandBars.FindControls(ID:=arrIdNum(lngId))
It is giving me a Run Time Error 91
Why is this?
Private Sub Workbook_Open()
EventHack
End Sub
Sub EventHack()
AssignMacro "JudgeRng"
End Sub
Private Sub AssignMacro(ByVal strProc As String)
Dim lngId As Long
Dim CtrlCbc As CommandBarControl
Dim CtrlCbcRet As CommandBarControls
Dim arrIdNum As Variant
' 295 Insert Cells from worksheet menu
' 296 Insert rows from worksheet menu
' 945 Insert from right click menu
arrIdNum = Array(295, 296, 3183)
For lngId = LBound(arrIdNum) To UBound(arrIdNum)
Set CtrlCbcRet = CommandBars.FindControls(ID:=arrIdNum(lngId))
For Each CtrlCbc In CtrlCbcRet
CtrlCbc.OnAction = strProc
Next
Set CtrlCbcRet = Nothing
Next
End Sub
http://www.mrexcel.com/forum/showthread.php?t=80626
I have placed it in Thisworkbook module. It is failing on the line:
Set CtrlCbcRet = CommandBars.FindControls(ID:=arrIdNum(lngId))
It is giving me a Run Time Error 91
Why is this?
Private Sub Workbook_Open()
EventHack
End Sub
Sub EventHack()
AssignMacro "JudgeRng"
End Sub
Private Sub AssignMacro(ByVal strProc As String)
Dim lngId As Long
Dim CtrlCbc As CommandBarControl
Dim CtrlCbcRet As CommandBarControls
Dim arrIdNum As Variant
' 295 Insert Cells from worksheet menu
' 296 Insert rows from worksheet menu
' 945 Insert from right click menu
arrIdNum = Array(295, 296, 3183)
For lngId = LBound(arrIdNum) To UBound(arrIdNum)
Set CtrlCbcRet = CommandBars.FindControls(ID:=arrIdNum(lngId))
For Each CtrlCbc In CtrlCbcRet
CtrlCbc.OnAction = strProc
Next
Set CtrlCbcRet = Nothing
Next
End Sub