Option Explicit
Dim mbCut As Boolean
Dim mRngSource As Range
Public Sub InitCutCopyPaste()
Application.OnKey "^X", "DoCut"
Application.OnKey "^x", "DoCut"
Application.OnKey "+{DEL}", "DoCut"
Application.OnKey "^C", "DoCopy"
Application.OnKey "^c", "DoCopy"
Application.OnKey "^{INSERT}", "DoCopy"
Application.OnKey "^V", "DoPaste"
Application.OnKey "^v", "DoPaste"
Application.OnKey "+{INSERT}", "DoPaste"
Application.OnKey "{ENTER}", "DoPaste"
Application.OnKey "~", "DoPaste"
Application.CellDragAndDrop = False
End Sub
Public Sub DoCut()
If TypeOf Selection Is Range Then
mbCut = True
Set mRngSource = Selection
Selection.Copy
Else
Set mRngSource = Nothing
Selection.Cut
End If
End Sub
Public Sub DoCopy()
If TypeOf Selection Is Range Then
mbCut = False
Set mRngSource = Selection
Selection.Copy
Else
Set mRngSource = Nothing
End If
Selection.Copy
End Sub
Public Sub DoPaste()
If Application.CutCopyMode And Not mRngSource Is Nothing Then
Selection.PasteSpecial xlValues
If mbCut Then mRngSource.ClearContents
Application.CutCopyMode = False
Else
ActiveSheet.Paste
End If
End Sub
|