EnergyStar
New Member
- Joined
- Jun 10, 2014
- Messages
- 1
Hello,
Thanks for viewing my thread. I am troubleshooting a macro enabled spreadsheet which adds a custom menu through vba. It does not have an Add-in but adds the menu before Help, so the custom menu appears under Add-Ins. The custom menu is dynamically created on workbook_open() and consists of a popup menu that includes two controls and three popup submenus.
The spreadsheet worked fine until I opened another instance of the same spreadsheet, resulting in a runtime 91 error.
The custom menu did not display properly after that. The three popup submenus are greyed out whenever the spreadsheet is opened, while the other two are unaffected.
here is the bit of code that enables the popup submenus depending on the worksheet tag. I have stepped through the code and verified that the menus are set to enabled and visible, yet they do not display on the menu bar.
I then looked for the control using the below code and did not find them.
However when I tried the following code, I was able to find the commandbar objects and deleted them.
My question:
Those controls were being created and enabled somewhere whenever the spreadsheet was run, and I would like to find out where. Can someone throw some light on what was happening with the spreadsheet and how I may re-enable the menu without including the code to first delete the controls created.
Thanks and any help is appreciated.
Thanks for viewing my thread. I am troubleshooting a macro enabled spreadsheet which adds a custom menu through vba. It does not have an Add-in but adds the menu before Help, so the custom menu appears under Add-Ins. The custom menu is dynamically created on workbook_open() and consists of a popup menu that includes two controls and three popup submenus.
The spreadsheet worked fine until I opened another instance of the same spreadsheet, resulting in a runtime 91 error.
The custom menu did not display properly after that. The three popup submenus are greyed out whenever the spreadsheet is opened, while the other two are unaffected.
here is the bit of code that enables the popup submenus depending on the worksheet tag. I have stepped through the code and verified that the menus are set to enabled and visible, yet they do not display on the menu bar.
Code:
If (Application.ActiveSheet.CodeName = "SomeName") Then
Application.CommandBars.FindControl(Tag:="SomeNameTag").Enabled = True
If (Application.ActiveSheet.CodeName = "SomeOtherName") Then
Application.CommandBars.FindControl(Tag:="SomeOtherNameTag").Enabled = True
I then looked for the control using the below code and did not find them.
Code:
Dim objCommandBar1 As Office.CommandBar
Dim objControl As Office.CommandBarControl
For Each objCommandBar In CommandBars
Set objControl = objCommandBar.FindControl(Tag:="SomeNameTag", Recursive:=True)
If Not (objControl Is Nothing) Then
Debug.Print objCommandBar.Name
End If
Next objCommandBar
However when I tried the following code, I was able to find the commandbar objects and deleted them.
Code:
Dim myPopupControls As Office.CommandBarControls
Dim PopupCtl As Office.CommandBarControl
Set myPopupControls = Application.CommandBars.FindControls(Tag:=s_PopupMenuTag)
If Not (myPopupControls Is Nothing) Then
For Each PopupCtl In myPopupControls
If Not (PopupCtl Is Nothing) Then
' Debug.Print PopupCtl.Name
' Debug.Print PopupCtl.ID
' Debug.Print PopupCtl.Enabled
' Debug.Print PopupCtl.Visible
PopupCtl.Delete
End If
Next PopupCtl
End If
My question:
Those controls were being created and enabled somewhere whenever the spreadsheet was run, and I would like to find out where. Can someone throw some light on what was happening with the spreadsheet and how I may re-enable the menu without including the code to first delete the controls created.
Thanks and any help is appreciated.