Disable "Format Cells" menu

OfficeUser

Well-known Member
Joined
Feb 4, 2010
Messages
544
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have been able to disable "Format" from the main excel menu, but am stumped trying to disable it in the right click menu. Does anyone know the trick to doing this? Thanks.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Here's a sample. I hope it helps.

Gary

Code:
Public Sub Test()

Dim oCommandBar As CommandBar
Dim oControl As CommandBarControl

Set oCommandBar = Application.CommandBars("Cell")

For Each oControl In oCommandBar.Controls
    Debug.Print oControl.Caption
    If InStr(1, oControl.Caption, "Format") Then
        oControl.Enabled = False
        'oControl.Delete 'or delete control if desired
    End If
Next oControl

'Use the following statement to restore "Cells" menu to "as installed" condition
'Application.CommandBars("Cell").Reset

End Sub
 
Upvote 0
Actually, using the code he has posted, and also using code I had to disable "Format" in the main excel menu, that does not work. I will say that you taught me something new as I did not know about that shortcut. Thanks.
 
Upvote 0
Thanks for the feedback. Glad it worked for you.

I would be inclined to let the user know why the "Format cells" option is disabled. Instead of disabling or removing the control you could change the "OnAction" property to display a user friendly message.

Maybe disable it after the user clicks it the first time and is given the notice. I find that it reduces the number of times I hear "my Excel menus are messed up".

Code:
oControl.OnAction = "MyUserMessage"

Public Sub MyUserMessage()

MsgBox "You are not authorized to format cells"
'Disable control here

End Sub

Gary
 
Upvote 0
You should also be aware that there are 2 Cell menus.
 
Upvote 0
That's a great suggestion, and I will likely use it. I have to share a spreadsheet with some folks that barely know the basics of excel. Not that it's a bad thing, but I am responsible for the overall effectiveness of the workbook.
 
Upvote 0
Gary's code disables the Format... items on the Cell menu, but there are actually two of them so you'd need to loop and disable both. There are also Format Cells commands on the 2 Row and 2 Column shortcut menus. I would use:
Code:
Dim oControl As CommandBarControl

For Each oControl In Application.CommandBars.FindControls(ID:=855)
   oControl.Enabled = False
   'oControl.Delete 'or delete control if desired
Next oControl

which will disable all copies of the Format Cells command, no matter which toolbar they are on. (2003 and prior anyway)
 
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,151
Members
452,891
Latest member
JUSTOUTOFMYREACH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top