Excel 2010 addin with menus not working in Excel 2013

jmholdermn

New Member
Joined
Jul 7, 2015
Messages
2
The addin I used in 2010 to access my macros via menu commands is not working in Excel 2013. I've read several posts that say its because the Analysis Tool Pack should load last, but I don't use the ATP, the only addin I have loading is mine. I've also read posts that say Excel 2013 uses SDI not MDI and there is usually a link but I must be missing something because I'm not seeing a solution.

When I install my adding and open Excel I get a run time error '9' Script out of range pointing to the following line:

Set MenuObject = Application.CommandBars(1). _
Controls.Add(Type:=msoControlPopup, _
Before:=PositionOrMacro, _
Temporary:=True)

Any help from the Excel Gurus would be greatly appreciated.

Here is the code I'm using to load my menus:

Set MenuObject = Application.CommandBars(1). _
Controls.Add(Type:=msoControlPopup, _
Before:=PositionOrMacro, _
Temporary:=True)
Sub CMR_Menu_Init()
' This sub should be executed when the workbook is opened.
' NOTE: There is no error handling in this subroutine

Dim MenuSheet As Worksheet
Dim MenuObject As CommandBarPopup
Dim MenuItem As Object
Dim SubMenuItem As CommandBarButton
Dim Row As Integer
Dim MenuLevel, NextLevel, PositionOrMacro, Caption, Divider, FaceID

Set MenuSheet = ThisWorkbook.Sheets("CMR_Menu") 'Location for menu data

Call CMR_Menu_Delete 'Make sure the menus aren't duplicated

Row = 2 'Initialize the row counter

Do Until IsEmpty(MenuSheet.Cells(Row, 1)) 'Add the menus, menu items and submenu items using data stored on MenuSheet
With MenuSheet
MenuLevel = .Cells(Row, 1)
Caption = .Cells(Row, 2)
PositionOrMacro = .Cells(Row, 3)
Divider = .Cells(Row, 4)
FaceID = .Cells(Row, 5)
NextLevel = .Cells(Row + 1, 1)
End With

Select Case MenuLevel
Case 1 ' Menu Header
' In Excel 2003 and earlier, this will create a commandbar or a dropdown at the top of the program
' In Excel 2007 and 2010 it creates a menu listing only accessible by clicking
' on the "Add In" menu item
Set MenuObject = Application.CommandBars(1). _
Controls.Add(Type:=msoControlPopup, _
Before:=PositionOrMacro, _
Temporary:=True)
MenuObject.Caption = Caption

Case 2 ' Top Tier Menu, fisrt usable section
' I use this section to separate like items
'Each entry in this level contains a submenu or is a standalone item
If NextLevel = 3 Then
Set MenuItem = MenuObject.Controls.Add(Type:=msoControlPopup)
Else
Set MenuItem = MenuObject.Controls.Add(Type:=msoControlButton)
MenuItem.OnAction = PositionOrMacro
End If
MenuItem.Caption = Caption
If FaceID <> "" Then
MenuItem.FaceID = FaceID
End If
If Divider Then
MenuItem.BeginGroup = True
End If
Case 3 ' SubMenu level
Set SubMenuItem = MenuItem.Controls.Add(Type:=msoControlButton)
SubMenuItem.Caption = Caption
SubMenuItem.OnAction = PositionOrMacro
If FaceID <> "" Then
SubMenuItem.FaceID = FaceID
End If
If Divider Then
SubMenuItem.BeginGroup = True
End If
End Select
Row = Row + 1
Loop

'################# CMR_Menu_Init #####################
End Sub

Sub CMR_Menu_Delete()
' Executed when the workbook is closed to delete the menu so other workbooks are not effected
' Deletes the Menus
Dim MenuSheet As Worksheet
Dim Row As Integer
Dim Caption As String
On Error Resume Next
Set MenuSheet = ThisWorkbook.Sheets("CMR_Menu")
Row = 2
Do Until IsEmpty(MenuSheet.Cells(Row, 1))
If MenuSheet.Cells(Row, 1) = 1 Then
Caption = MenuSheet.Cells(Row, 2)
Application.CommandBars(1).Controls(Caption).Delete
End If
Row = Row + 1
Loop
On Error GoTo 0

'################# CMR_Menu_Delete #####################
End Sub

:oops:

John
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Forum statistics

Threads
1,214,827
Messages
6,121,816
Members
449,049
Latest member
cybersurfer5000

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top