Private Sub Worksheet_Change(ByVal Target As Range)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' This code will undo PASTE and instead show a message asking for Pasting as Values. ' This allow you to retain FORMATS in all of the cells in all of the sheets, but will ' also allow the user to COPY and PASTE data ' Since this subroutine is located in an Object Module, it should only affect this worksheet. ' Just in case, Disable and EnableEvents lines have been added in Module_ConsistencyChecks, Module_Output ' and Module_Reset to avoid EventLoops '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Dim UndoString As String Dim Msg, Style, Title, Response, MyString ' For the MsgBox On Error Resume Next ' Next line is prone to error UndoString = Application.CommandBars("Standard").Controls("復原(&U)").List(1)
If Left(UndoString, 2) = "貼上" And UndoString <> "選擇性貼上" Then Application.ScreenUpdating = False Application.EnableEvents = False Application.Undo Msg = _ "You are pasting information. Doing that will modify the Data Validation and corrupt the file." & _ "The operation was undone. If you want to paste data, please select paste as values. Thanks!" ' Define message. Style = vbOKOnly ' Define buttons. Title = "Invalid Action" ' Define title. Response = MsgBox(Msg, Style, Title) Worksheets("Loan_Information").Protect End If
Application.ScreenUpdating = True Application.EnableEvents = True On Error GoTo 0 End Sub