Gringoire
Board Regular
- Joined
- Nov 18, 2016
- Messages
- 71
- Office Version
- 365
- Platform
- Windows
Hello guys,
To avoid importing undesired wrong external references in my sheet by a User, I found this snipped on the internet. It works correctly replacing a paste by a pastevalues.
The only issue is when I use an internal VBA procedure to programmatically paste some range :
1) it rise an error on Application.Undo line.
2) it prevent my Paste operation (that is in this case required by myself)
So, my question is: is there a way to detect if the paste operation comes from a User (unwanted) action or from a (wanted) code routine?
many thanks
To avoid importing undesired wrong external references in my sheet by a User, I found this snipped on the internet. It works correctly replacing a paste by a pastevalues.
The only issue is when I use an internal VBA procedure to programmatically paste some range :
1) it rise an error on Application.Undo line.
2) it prevent my Paste operation (that is in this case required by myself)
So, my question is: is there a way to detect if the paste operation comes from a User (unwanted) action or from a (wanted) code routine?
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Application.CutCopyMode = xlCopy Then
Application.EnableEvents = False
Application.Undo
Target.PasteSpecial Paste:=xlPasteValues
Application.EnableEvents = True
End If
End Sub
many thanks