Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling "cut" from excel with vba

Tags:

excel

vba

I've read many threads on this topic, but the code I have found there doesn't seem to work. I am trying to disable the "cut" function from an excel spreadsheet and I would like the icon to grey out.

I have been using this code:

Sub WorkSheet_Activate()
Application.CommandBars.FindControl(ID:=21).Enabled = False 
End Sub

However, I can still use the "cut" function without any problem.... Also I know there are some functions that allow you to disable cut/copy/paste, but I still want copy and paste to be allowed in this spreadsheet.

Thanks in advance for your help!

Kristen

like image 373
Kristen Avatar asked Jan 16 '17 16:01

Kristen


People also ask

How do I turn off cut in Excel?

In the workbook you need to disable the cut, copy and paste functions, please press the Alt + F11 keys simultaneously to open the Microsoft Visual Basic for Applications window. 3.


1 Answers

Check the link for the reference - Disable Cut

Try something like this:

Option Explicit
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _
ByVal Target As Excel.Range)

Select Case Application.CutCopyMode
Case Is = False
'do nothing
Case Is = xlCopy
'do nothing
Case Is = xlCut
MsgBox "Please DO NOT Cut and Paste. Use Copy and Paste; then delete the source."
Application.CutCopyMode = False 'clear clipboard and cancel cut
End Select

End Sub

Hope it helps.

like image 196
Ranadip Dutta Avatar answered Nov 14 '22 21:11

Ranadip Dutta