B
Boycey
Windows 2000
Office XP
I have created an Excel add-in which creates a new menu item on
opening, and deletes it in closing. The menu works fine on my WinXP /
Office XP machine, and on a number of users' Win2k/Office Xp machines.
However, on certain computers, the add-in causes Excel to freeze on
opening. I have the following code in the "ThisWorkbook" section:
[START CODE]
Option Explicit
Private Sub Workbook_BeforeClose(Cancel As Boolean)
RemoveMenu
End Sub
Sub workbook_open()
NewMenu
End Sub
[END CODE]
which calls procedure "NewMenu" on open. "NewMenu" contains the
following code:
[START CODE]
Sub NewMenu()
Dim aMenu As Variant
Set aMenu = MenuBars(xlWorksheet).Menus.Add("IAD")
aMenu.MenuItems.Add "Format for MIDAS", OnAction:="multexformat"
aMenu.MenuItems.Add "Create labels", OnAction:="CreateLabels"
aMenu.MenuItems.Add "-"
aMenu.MenuItems.Add "Save rating change", OnAction:="pastevalues"
aMenu.MenuItems.Add "Format Holdings Report",
OnAction:="HoldingReport"
aMenu.MenuItems.Add "-"
aMenu.MenuItems.Add "About Add-in", OnAction:="AboutAddin"
aMenu.MenuItems("Save rating change").Enabled = False
aMenu.MenuItems("Format holdings report").Enabled = False
Select Case GetNetworkName
Case "tdonovan", "mnakai"
aMenu.MenuItems("Format holdings report").Enabled = True
Case "dboyce", "nharris"
aMenu.MenuItems("Format holdings report").Enabled = True
aMenu.MenuItems("Save rating change").Enabled = True
End Select
End Sub
[END CODE]
When I open Excel, the IAD menu appears, but Excel freezes, the menus
do not respond, and no "Book1" new file is created.
If I remove the NewMenu command from workbook_open, Excel opens as
normal. I can the run the workbook_open procedure from VBA with no
problem at all.
I cannot find anything wrong with the code - indeed, there can't be,
as it runs fine when Excel has already been opened. It is only when
it is run during the opening of Excel, on the Workbook_open event,
that problems occur.
This is a very frustrating problem, not least because the add-in works
fine on a number of other computers running exactly the same versions
of Windows and Office. If anybody has any suggestions, I would be
very grateful.
Thanks
Dom
Office XP
I have created an Excel add-in which creates a new menu item on
opening, and deletes it in closing. The menu works fine on my WinXP /
Office XP machine, and on a number of users' Win2k/Office Xp machines.
However, on certain computers, the add-in causes Excel to freeze on
opening. I have the following code in the "ThisWorkbook" section:
[START CODE]
Option Explicit
Private Sub Workbook_BeforeClose(Cancel As Boolean)
RemoveMenu
End Sub
Sub workbook_open()
NewMenu
End Sub
[END CODE]
which calls procedure "NewMenu" on open. "NewMenu" contains the
following code:
[START CODE]
Sub NewMenu()
Dim aMenu As Variant
Set aMenu = MenuBars(xlWorksheet).Menus.Add("IAD")
aMenu.MenuItems.Add "Format for MIDAS", OnAction:="multexformat"
aMenu.MenuItems.Add "Create labels", OnAction:="CreateLabels"
aMenu.MenuItems.Add "-"
aMenu.MenuItems.Add "Save rating change", OnAction:="pastevalues"
aMenu.MenuItems.Add "Format Holdings Report",
OnAction:="HoldingReport"
aMenu.MenuItems.Add "-"
aMenu.MenuItems.Add "About Add-in", OnAction:="AboutAddin"
aMenu.MenuItems("Save rating change").Enabled = False
aMenu.MenuItems("Format holdings report").Enabled = False
Select Case GetNetworkName
Case "tdonovan", "mnakai"
aMenu.MenuItems("Format holdings report").Enabled = True
Case "dboyce", "nharris"
aMenu.MenuItems("Format holdings report").Enabled = True
aMenu.MenuItems("Save rating change").Enabled = True
End Select
End Sub
[END CODE]
When I open Excel, the IAD menu appears, but Excel freezes, the menus
do not respond, and no "Book1" new file is created.
If I remove the NewMenu command from workbook_open, Excel opens as
normal. I can the run the workbook_open procedure from VBA with no
problem at all.
I cannot find anything wrong with the code - indeed, there can't be,
as it runs fine when Excel has already been opened. It is only when
it is run during the opening of Excel, on the Workbook_open event,
that problems occur.
This is a very frustrating problem, not least because the add-in works
fine on a number of other computers running exactly the same versions
of Windows and Office. If anybody has any suggestions, I would be
very grateful.
Thanks
Dom