![]() |
enable menu command not working
I want to disable or enable the Delete command of the edit menu based on what
is currently selected on a worksheet. I put the following code in the Selection Change event of the worksheet that I want to control. The code works perfectly to disable the command on the edit menu. Unfortunately, I get a run-time error (Error 5: Invalid Procedure Call or argument) when I try to enable the command. Why would the code work properly on the first line and generate an error on the second line? I would greatly appreciate any help determining what is going on with my spreadsheet. Mary Private Sub Worksheet_SelectionChange(ByVal Target As Range) 'PREVENT USER FROM DELETING COLUMNS If Selection.Address = Target.EntireColumn.Address Then Application.CommandBars("worksheet menu bar").Controls("edit").Controls("delete").Enabled = False Else: IsFormulaCardOpen 'CANNOT FIGURE OUT WHY THIS LINE DOES NOT WORK TO REACTIVATE MENU OPTION If OpenFC = False Then _ Application.CommandBars("worksheet menu bar").Controls("edit").Controls("delete").Enabled = True End If End Sub |
enable menu command not working
Hi Mary,
Try changing "delete" to "delete..." Regards, Peter T "Mary" wrote in message ... I want to disable or enable the Delete command of the edit menu based on what is currently selected on a worksheet. I put the following code in the Selection Change event of the worksheet that I want to control. The code works perfectly to disable the command on the edit menu. Unfortunately, I get a run-time error (Error 5: Invalid Procedure Call or argument) when I try to enable the command. Why would the code work properly on the first line and generate an error on the second line? I would greatly appreciate any help determining what is going on with my spreadsheet. Mary Private Sub Worksheet_SelectionChange(ByVal Target As Range) 'PREVENT USER FROM DELETING COLUMNS If Selection.Address = Target.EntireColumn.Address Then Application.CommandBars("worksheet menu bar").Controls("edit").Controls("delete").Enabled = False Else: IsFormulaCardOpen 'CANNOT FIGURE OUT WHY THIS LINE DOES NOT WORK TO REACTIVATE MENU OPTION If OpenFC = False Then _ Application.CommandBars("worksheet menu bar").Controls("edit").Controls("delete").Enabled = True End If End Sub |
enable menu command not working
Thank you. It works now.
"Peter T" wrote: Hi Mary, Try changing "delete" to "delete..." Regards, Peter T "Mary" wrote in message ... I want to disable or enable the Delete command of the edit menu based on what is currently selected on a worksheet. I put the following code in the Selection Change event of the worksheet that I want to control. The code works perfectly to disable the command on the edit menu. Unfortunately, I get a run-time error (Error 5: Invalid Procedure Call or argument) when I try to enable the command. Why would the code work properly on the first line and generate an error on the second line? I would greatly appreciate any help determining what is going on with my spreadsheet. Mary Private Sub Worksheet_SelectionChange(ByVal Target As Range) 'PREVENT USER FROM DELETING COLUMNS If Selection.Address = Target.EntireColumn.Address Then Application.CommandBars("worksheet menu bar").Controls("edit").Controls("delete").Enabled = False Else: IsFormulaCardOpen 'CANNOT FIGURE OUT WHY THIS LINE DOES NOT WORK TO REACTIVATE MENU OPTION If OpenFC = False Then _ Application.CommandBars("worksheet menu bar").Controls("edit").Controls("delete").Enabled = True End If End Sub |
All times are GMT +1. The time now is 04:39 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com