ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Disable the Delete Control in the Edit Menu (https://www.excelbanter.com/excel-programming/368057-disable-delete-control-edit-menu.html)

Virtual Hillbilly

Disable the Delete Control in the Edit Menu
 
I'd appreciate any help with the following. While trying to disable the
"Delete" control on the "Edit" CommandBar, I get an "Run-time error '5':
Invalid call or argument" error. However, the code works for the "Delete
Sheet" Control. Any thoughts on what might be going on??? The macro works
if I substitute "11" as the index, but I'm not confident this will be
universal for all computers the macro might be running on if someone's menu
has been customized. Is this a correct assumption? The code being used is:

Sub Disable_RowDelete()

Application.CommandBars("Row").Enabled = False
Application.CommandBars("Edit").Controls("Delete Sheet").Enabled = False
Application.CommandBars("Edit").Controls("Delete") .Enabled = False

End Sub

Sub Enable_RowDelete()

Application.CommandBars("Row").Enabled = True
Application.CommandBars("Edit").Controls("Delete Sheet").Enabled = True
Application.CommandBars("Edit").Controls("Delete") .Enabled = True

End Sub



Ron de Bruin

Disable the Delete Control in the Edit Menu
 
Note that it is
Delete...

But use the ID

Sub test()
Application.CommandBars("Worksheet Menu Bar").FindControl _
(ID:=478, Recursive:=True).Enabled = False
End Sub

See
http://www.rondebruin.nl/menuid.htm


--
Regards Ron de Bruin
http://www.rondebruin.nl



"Virtual Hillbilly" wrote in message
...
I'd appreciate any help with the following. While trying to disable the
"Delete" control on the "Edit" CommandBar, I get an "Run-time error '5':
Invalid call or argument" error. However, the code works for the "Delete
Sheet" Control. Any thoughts on what might be going on??? The macro works
if I substitute "11" as the index, but I'm not confident this will be
universal for all computers the macro might be running on if someone's menu
has been customized. Is this a correct assumption? The code being used is:

Sub Disable_RowDelete()

Application.CommandBars("Row").Enabled = False
Application.CommandBars("Edit").Controls("Delete Sheet").Enabled = False
Application.CommandBars("Edit").Controls("Delete") .Enabled = False

End Sub

Sub Enable_RowDelete()

Application.CommandBars("Row").Enabled = True
Application.CommandBars("Edit").Controls("Delete Sheet").Enabled = True
Application.CommandBars("Edit").Controls("Delete") .Enabled = True

End Sub






All times are GMT +1. The time now is 10:33 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com