This macro works, but this doesent. Any ideas please ?
Posted by David Bissland on October 28, 2001 1:41 PM
Hi,
I am using Excel 97 SR-2
These first 2 macros work OK. They firstly delete the "Save" option in the "File" Menu, and then restore it.
Sub menuItem_Delete()
Dim myCmd As Object
Set myCmd = CommandBars("Worksheet menu bar").Controls("File")
myCmd.Controls("Save").Delete
End Sub
Sub menuItem_Restore()
Dim myCmd As Object
Set myCmd = CommandBars("Worksheet menu bar").Controls("File")
' Id 3 refers to the Save menu item control.
myCmd.Controls.Add Type:=msoControlButton, Id:=3, Before:=5
End Sub
************************************************
If I change the above macros to try and delete and reinstate the "Macro" menu item in the Tools menu, (see below)the first part menuItem_Delete1() works OK, but when I run menuItem_Restore1() I get a "Run time error 5, Invalid Procedure Call or Argument" error message.
Sub menuItem_Delete1()
Dim myCmd As Object
Set myCmd = CommandBars("Worksheet menu bar").Controls("Tools")
myCmd.Controls("Macro").Delete
End Sub
Sub menuItem_Restore1()
Dim myCmd As Object
Set myCmd = CommandBars("Worksheet menu bar").Controls("Tools")
' Id 30017 refers to the Macro menu item control.
myCmd.Controls.Add Type:=msoControlButton, Id:=30017, Before:=11
End Sub
Any ideas appreciated.
Thanks
David