Am I creating a problem with this code to disable user funct

jgoulart

Board Regular
Joined
Feb 16, 2002
Messages
62
I have tested this code a little and it seems to work fine in taking away user control and then restoring it when another workbook is active but am I going to run into other problems down the road using it?

Dim CB As CommandBar
Dim C As CommandBarControl
Dim ID
Option Explicit

Private Sub Workbook_Activate()
Disable_RightClick_Toolbar
End Sub

Private Sub Workbook_Deactivate()
Enable_RightClick_ToolBar
End Sub

Sub Disable_RightClick_Toolbar()
ID = 30017
For Each CB In Application.CommandBars
Set C = CB.FindControl(ID:=ID, recursive:=True)
If Not C Is Nothing Then C.Enabled = False
Next
Application.CommandBars("Toolbar List").Enabled = False
Application.CommandBars("Visual Basic").Enabled = False
Dim cntrl As CommandBarControl
With CommandBars("Worksheet Menu Bar")
.Controls("file").Enabled = False
.Controls("edit").Enabled = False
.Controls("view").Enabled = False
.Controls("insert").Enabled = False
.Controls("file").Enabled = False
.Controls("data").Enabled = False
.Controls("tools").Enabled = False
.Controls("format").Enabled = False


End With
End Sub



Sub Enable_RightClick_ToolBar()

ID = 30017
For Each CB In Application.CommandBars
Set C = CB.FindControl(ID:=ID, recursive:=True)
If Not C Is Nothing Then C.Enabled = True
Next
Application.CommandBars("ToolBar List").Enabled = True
Application.CommandBars("Visual Basic").Enabled = True
Dim cntrl As CommandBarControl
With CommandBars("Worksheet Menu Bar")
.Controls("file").Enabled = True
.Controls("edit").Enabled = True
.Controls("view").Enabled = True
.Controls("insert").Enabled = True
.Controls("file").Enabled = True
.Controls("data").Enabled = True
.Controls("tools").Enabled = True
.Controls("format").Enabled = True

End With

End Sub


Thanks,

John
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,223,382
Messages
6,171,771
Members
452,422
Latest member
rlynchbro

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