, , Paste
, Excel "On-Paste" ( ), 2003 . "" 2003 ( , Sheet_Activate()):
Sub SetPasteTrap(Mode As Boolean)
' TRUE sets the trap, FALSE releases trap
If Mode Then
Application.CommandBars("Edit").Controls("Paste").OnAction = "TrappedPaste"
Application.CommandBars("Edit").Controls("Paste Special...").OnAction = "TrappedPaste"
Application.CommandBars("Cell").Controls("Paste").OnAction = "TrappedPaste"
Application.CommandBars("Cell").Controls("Paste Special...").OnAction = "TrappedPaste"
Application.OnKey "^v", "TrappedPaste"
Else
Application.CommandBars("Edit").Controls("Paste").OnAction = ""
Application.CommandBars("Edit").Controls("Paste Special...").OnAction = ""
Application.CommandBars("Cell").Controls("Paste").OnAction = ""
Application.CommandBars("Cell").Controls("Paste Special...").OnAction = ""
Application.OnKey "^v"
End If
End Sub
, Ctrl-V - . OnAction ,
Sub TrappedPaste()
If ActiveSheet.ProtectContents Then
' as long as sheet is protected, we don't paste at all
MsgBox "Sheet is protected, all Paste/PasteSpecial functions are disabled." & vbCrLf & _
"At your own risk you may unprotect the sheet." & vbCrLf & vbCrLf & _
"When unprotected, you can copy/paste from other text, WORD, HTML or EXCEL files." & vbCrLf & _
"All Paste operations will implicitly be executed as PasteSpecial/Values", _
vbOKOnly, "Paste"
Exit Sub
End If
' silently do a PasteSpecial/Values
On Error GoTo TryExcel
' try to paste text
ActiveSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:=False
Exit Sub
TryExcel:
On Error GoTo DoesntWork
Selection.PasteSpecial xlPasteValues
Exit Sub
DoesntWork:
MsgBox "Sorry - wrong format for pasting", vbExclamation + vbOKOnly, "PasteSpecial ..."
End Sub
, , , (excel, text, html ..)
TrappedPaste() ,
1) / ( )
2)
3) ,
4) the target cell fulfills the condition of the absence of blocking, verification or similar
5) re-protect the target sheet
6) blank hidden sheet / range
Please note that with this design, the user will not be able to use the UNDO function!
Hope this helps - Good Luck MikeD