Hi there,
I am not very good at VBA....
I would like a vba script to trigger when a paste event occurs on one of the spreadsheet...
How????
Many many thanks
Ken
Printable View
Hi there,
I am not very good at VBA....
I would like a vba script to trigger when a paste event occurs on one of the spreadsheet...
How????
Many many thanks
Ken
You need to use the Worksheet_Change event for a single Worksheet or the Workbook_SheetChange event if you want thsi to work for all sheets in the book.
The challenge here is to see if the value of Target equals the value of the clipboard.
To return the value from the clipboard, create a Dataobject and use the GetFromClipboard method. then you can compare the values and if they are the same - a paste has happened.
The following should give you a start.
Note: you will need to add a reference to the Forms library to your project, as the DataObjectt is not native to Excel.
VB Code:
Private Sub Worksheet_Change(ByVal Target As Range) Dim MyObj As DataObject Dim PasteVal As String Set MyObj = New DataObject MyObj.GetFromClipboard PasteVal = MyObj.GetText(1) If Target.Text = PasteVal Then 'insert code here End If End Sub