xuanhoa7604
Thành viên hoạt động



- Tham gia
- 9/6/08
- Bài viết
- 169
- Được thích
- 82
- Nghề nghiệp
- Giáo viên
Bác nào biết cách làm cho file excel không thực hiện lệnh cut được (nhưng vẫn copy được) không? Cám ơn các bác nhiều.
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
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call EnableCut
End Sub
Private Sub Workbook_Open()
Call DisableCut
End Sub
[B]Private Sub Workbook_Activate()[/B]
Dim oCtrl As Office.CommandBarControl
'Disable all Cut menus
For Each oCtrl In Application.CommandBars.FindControls(ID:=21)
oCtrl.Enabled = False
Next oCtrl
Application.CellDragAndDrop = False
[B]End Sub[/B]
[B]Private Sub Workbook_Deactivate()[/B]
Dim oCtrl As Office.CommandBarControl
'Enable all Cut menus
For Each oCtrl In Application.CommandBars.FindControls(ID:=21)
oCtrl.Enabled = True
Next oCtrl
Application.CellDragAndDrop = True
[B]End Sub[/B]
[B]Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)[/B]
With Application
.CellDragAndDrop = False
.CutCopyMode = False 'Clear clipboard
End With
[B]End Sub[/B]
Đồng ý là phương pháp thì có nhiều, nhưng tôi chưa hiểu lắm tại sao ta chống "Cut" nhưng lại cho phép "Copy"Bác nào biết cách làm cho file excel không thực hiện lệnh cut được (nhưng vẫn copy được) không? Cám ơn các bác nhiều.
Đồng ý là phương pháp thì có nhiều, nhưng tôi chưa hiểu lắm tại sao ta chống "Cut" nhưng lại cho phép "Copy"
Mục đích để làm gì?
Bạn cấm thế thì tôi copy... Paste... xong rồi Delete... Được không?
Đương nhiên nó phải thay đổi rồi, đây là tính năng của Excel màmình làm chương trình tính điểm. Mình có gặp phải lỗi như sau. bạn thử làm xem nha.
Đánh vào ô c3 công thức =A1+B1 xong enter.
nhập vào ô a1 và b1 lần lượt hai số nào đó (ví dụ 2 và 6 khi đó ô c3 có kết quả là 8).
chọn vùng A1:B1 và chọn lệnh cut.
chọn ô b1 và thực hiện lệnh paste.
bạn thử quay lại ô c1 xem công thức mà xem, nó đã bị thay đổi rồi.