Disable "Cut" command


Posted by Jamie on May 24, 2000 4:51 PM

Hi,
I've got an excel 97 sheet in which I would like to have the "Cut" command disabled. Can that be done? Things like the "Edit" then "Cut" option, the "cut icon", and "ctrl-x".
Can someone help me out. By the way, I cannot just protect the worksheet. I need to keep it unprotected.
Thank you.
Jamie

Posted by Ivan Moala on May 25, 2000 12:58 AM

Try this little trick using xl4macro

Under Thisworkbook objectOption Explicit

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call EnableCut
End Sub

Private Sub Workbook_Open()
Call DisableCut
End Sub

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Excel.Range)
ExecuteExcel4Macro ("GET.WORKSPACE(10)")
End Sub

In a module put

Option Explicit

Sub DisableCut()
Application.OnKey "{Delete}", "NoNo"
End Sub
Sub EableCut()
Application.OnKey "{Delete}", ""
End Sub

Sub NoNo()
MsgBox "Don't do that!"
End Sub


This should disable the cut & paste et All

Ivan

Posted by Ivan Moala on May 25, 2000 1:03 AM

Woops
Change Sub EableCut() to Sub EnableCut()

Ivan

Posted by Ivan Moala on May 25, 2000 1:30 AM

To restore it back to normal the code should read
Sub EnableCut()
Application.OnKey "{Delete}"
End Sub


Ivan

Posted by JAF on May 25, 2000 3:40 AM

Ivan

I have just tried this and it works very nicely indeed.

Just one point I would make is that it still allows the user to "break" the workbook by dragging a cell to another location or to replace an existing cell.

Is there any way of stopping that from happening?

Over to you, oh Excel guru!!!


JAF

Posted by Ivan Moala on May 25, 2000 7:14 AM

Jaf
Yes you are right
Try this, not totally infaleble BUT..... then


Sub DisableCut()
'Disable MAIN
Application.CommandBars("Worksheet Menu Bar").Enabled = False
'Disable right click on Sheet Cells which also gives you option to cut
Application.CommandBars("Cell").Enabled = False
'Disable Find & Replace buttons
Application.CommandBars("Edit").Controls.Item("Find...").Enabled = False
Application.CommandBars("Edit").Controls.Item("Replace...").Enabled = False
'Divert "Delete" KEY
Application.OnKey ("{Delete}"), "NoNo"
'Divert Ctrl + F = Find
Application.OnKey "^f", "NoNo"
'Divert Ctrl + H = Replace
Application.OnKey "^h", "NoNo"
'Disable Cell drag & Drop
Application.CellDragAndDrop = False
End Sub
Sub EnableCut()
Application.CommandBars("Worksheet Menu Bar").Enabled = True
Application.CommandBars("Worksheet Menu Bar").Reset
Application.CommandBars("Cell").Enabled = True
Application.OnKey "{Delete}"
Application.OnKey "^f"
Application.OnKey "^h"
Application.CellDragAndDrop = True
End Sub

Ivan

Posted by Ivan Moala on May 25, 2000 5:28 PM

Hi Nils & Jaf

Just as a matter of interest, are you usingthis
as a means of protection against changes ??
If so then thee is another way, as I took this literally as disabling the cut, and that if the overall
objective is to allow certain functions BUT to not change the
sheet then this is another way (without protecting the sheet)

Ivan

Posted by Jamie on May 25, 2000 11:14 PM

Ivan,
I'm happy you took the time to look into this for me and I've run the formulas you posted and they work just as you say however, I still would like to have the ability to paste.
What I am doing is, I've got a timesheet, it is protected but, the cells where people enter there "in" & "out" times are unlocked. Now for the reason that people often work the same "in" & "out" time throughout the week, it's nice to be able to have the ability to copy and paste from one cell to another. But, where I'm running into a problem is when someone enters a time into a wrong cell (i.e. put an entry on Tuesday's line when they meant to put in on Monday's) and then they try to cut it out and paste it into the right spot. For some reason, when that happens, the cell that is cut loses its cell formatting (I think that the new cell defaults back to a "general" format) and that then screws up my formulas.
So the short of it is, is there a way to simply disable the "cut" command while still having the "copy" & "paste" enabled?
Thanks for all the help you've given so far. I do appreciate it.
Jamie

Posted by Ivan Moala on May 26, 2000 4:04 AM

jammie to diable the cut and the other cut actions
then use this instead.
Note: A seasoned user who really wants it can still
get @ it.

In a Module put this in;

Sub DisableCut()

On Error Resume Next
'Disable RigthClick on SheetCells which also gives you the option to cut
Application.CommandBars("Cell").Enabled = False

'Disable Cut button
Application.CommandBars("Standard").Controls.Item("Cut").Enabled = False

'Disable Cut button
Application.CommandBars("Edit").Controls.Item("Cut").Enabled = False

'Divert Ctrl + X = Cut
Application.OnKey "^x", "NoNo"

'Divert "Delete" KEY
Application.OnKey ("{Delete}"), "NoNo"

'Disable Cell drag & Drop
Application.CellDragAndDrop = False
End Sub


Sub EnableCut()
Application.CommandBars("Edit").Controls.Item("Cut").Enabled = True
Application.CommandBars("Standard").Controls.Item("Cut").Enabled = True
Application.CommandBars("Cell").Enabled = True
Application.OnKey "^x"
Application.OnKey "{Delete}"
Application.CellDragAndDrop = True
End Sub

Sub NoNo()
Dim MyMsg As String
Dim Lf As String
Lf = Chr(13)
MyMsg = "Please Don't do that!......" & Lf
MyMsg = MyMsg & "The integrety of the Data" & Lf
MyMsg = MyMsg & "may be corrupted by this action." & Lf
MyMsg = MyMsg & "Please use Copy & Paste." & Lf & Lf
MyMsg = MyMsg & "Thanks"
MsgBox MyMsg, vbInformation, "Data Integrity"
End Sub

In the Thisworkbook put this in;

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call EnableCut
End Sub

Private Sub Workbook_Open()
Call DisableCut
End Sub

Ivan



Posted by Jamie on May 26, 2000 11:28 AM

Ivan,
this is excellent. It is exactly what I needed. Thanks so much for all of you help. You da man!!!
Jamie