close

Hello all, If you need to disable the quot;CUTquot; feature of Excel within a
worksheet then the following works fine. The code disables the quot;CUTquot;
while you are within your file and restores the quot;CUTquot; function when you
exit your file - it stops cutting using shortcut keys or toolbar
functions. Please feel free to use the following - if you find you can
make the following VBA code better please feel free to reply to this
thread.

-- Place the following VBA in the quot;ThisWorkbookquot; area --

Private Sub Workbook_Open()

Run quot;DisableCutquot;
Run quot;Find_Disable_Commandsquot;

End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Run quot;EnableCutquot;
Run quot;Find_Enable_Commandsquot;

End Sub

-- Place the following VBA in a new Module --

Sub DisableCut()
On Error Resume Next
With Application
'disables shortcut keys
.OnKey quot;^xquot;, quot;quot;
'Disables Cut
.CommandBars(quot;Standardquot;).FindControl(ID:=21).Enabl ed = False
.CommandBars(quot;Editquot;).FindControl(ID:=21).Enabled = False
.CommandBars(quot;Cellquot;).FindControl(ID:=21).Enabled = False
.CommandBars(quot;Columnquot;).FindControl(ID:=21).Enabled = False
.CommandBars(quot;Rowquot;).FindControl(ID:=21).Enabled = False
.CommandBars(quot;Buttonquot;).FindControl(ID:=21).Enabled = False
.CommandBars(quot;XLM Cellquot;).FindControl(ID:=21).Enabled = False
.CommandBars(quot;Formula Barquot;).FindControl(ID:=21).Enabled = False
.CommandBars(quot;Queryquot;).FindControl(ID:=21).Enabled = False
.CommandBars(quot;Query Layoutquot;).FindControl(ID:=21).Enabled = False
.CommandBars(quot;Object/Plotquot;).FindControl(ID:=21).Enabled = False
.CommandBars(quot;Phonetic Informationquot;).FindControl(ID:=21).Enabled =
False
.CommandBars(quot;Shapesquot;).FindControl(ID:=21).Enabled = False
.CommandBars(quot;Inactive Chartquot;).FindControl(ID:=21).Enabled = False
.CommandBars(quot;ActiveX Controlquot;).FindControl(ID:=21).Enabled =
False
.CommandBars(quot;OLE Objectquot;).FindControl(ID:=21).Enabled = False
.CommandBars(quot;Excel Controlquot;).FindControl(ID:=21).Enabled = False
.CommandBars(quot;WordArt Contex Menuquot;).FindControl(ID:=21).Enabled =
False
.CommandBars(quot;Curvequot;).FindControl(ID:=21).Enabled = False
.CommandBars(quot;Pictures Contex Menuquot;).FindControl(ID:=21).Enabled =
False
.CommandBars(quot;Rotate Modequot;).FindControl(ID:=21).Enabled = False
.CommandBars(quot;Connectorquot;).FindControl(ID:=21).Enab led = False
.CommandBars(quot;Script Anchor Popupquot;).FindControl(ID:=21).Enabled =
False
.CommandBars(quot;Worksheet Menu Barquot;).FindControl(ID:=21).Enabled =
False
End With
End Sub

Sub EnableCut()
On Error Resume Next
With Application
'enables shortcut keys
.OnKey quot;^xquot;
'Enables Cut
.CommandBars(quot;Standardquot;).FindControl(ID:=21).Enabl ed = True
.CommandBars(quot;Editquot;).FindControl(ID:=21).Enabled = True
.CommandBars(quot;Cellquot;).FindControl(ID:=21).Enabled = True
.CommandBars(quot;Columnquot;).FindControl(ID:=21).Enabled = True
.CommandBars(quot;Rowquot;).FindControl(ID:=21).Enabled = True
.CommandBars(quot;Buttonquot;).FindControl(ID:=21).Enabled = True
.CommandBars(quot;XLM Cellquot;).FindControl(ID:=21).Enabled = True
.CommandBars(quot;Formula Barquot;).FindControl(ID:=21).Enabled = True
.CommandBars(quot;Queryquot;).FindControl(ID:=21).Enabled = True
.CommandBars(quot;Query Layoutquot;).FindControl(ID:=21).Enabled = True
.CommandBars(quot;Object/Plotquot;).FindControl(ID:=21).Enabled = True
.CommandBars(quot;Phonetic Informationquot;).FindControl(ID:=21).Enabled =
True
.CommandBars(quot;Shapesquot;).FindControl(ID:=21).Enabled = True
.CommandBars(quot;Inactive Chartquot;).FindControl(ID:=21).Enabled = True
.CommandBars(quot;ActiveX Controlquot;).FindControl(ID:=21).Enabled = True
.CommandBars(quot;OLE Objectquot;).FindControl(ID:=21).Enabled = True
.CommandBars(quot;Excel Controlquot;).FindControl(ID:=21).Enabled = True
.CommandBars(quot;WordArt Contex Menuquot;).FindControl(ID:=21).Enabled =
True
.CommandBars(quot;Curvequot;).FindControl(ID:=21).Enabled = True
.CommandBars(quot;Pictures Contex Menuquot;).FindControl(ID:=21).Enabled =
True
.CommandBars(quot;Rotate Modequot;).FindControl(ID:=21).Enabled = True
.CommandBars(quot;Connectorquot;).FindControl(ID:=21).Enab led = True
.CommandBars(quot;Script Anchor Popupquot;).FindControl(ID:=21).Enabled =
True
.CommandBars(quot;Worksheet Menu Barquot;).FindControl(ID:=21).Enabled =
True
End With
End Sub

Sub Find_Disable_Commands()
Dim myControls As CommandBarControls
Dim ctl As CommandBarControl
Set myControls = CommandBars.FindControls _
(Type:=msoControlButton, ID:=21) '21 = cut
For Each ctl In myControls
ctl.Enabled = False
Next ctl
End Sub

Sub Find_Enable_Commands()
Dim myControls As CommandBarControls
Dim ctl As CommandBarControl
Set myControls = CommandBars.FindControls _
(Type:=msoControlButton, ID:=21) '21 = cut
For Each ctl In myControls
ctl.Enabled = True
Next ctl
End Sub

Save the file then re-start Excel and the quot;CUTquot; should be disabled.--
sparx
------------------------------------------------------------------------
sparx's Profile: www.excelforum.com/member.php...oamp;userid=16787
View this thread: www.excelforum.com/showthread...hreadid=537613

全站熱搜
創作者介紹
創作者 software 的頭像
software

software

software 發表在 痞客邦 留言(0) 人氣()