|
-
Oct 17th, 2005, 03:51 PM
#1
Thread Starter
Frenzied Member
Detect a past event?
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
If you find my thread helpful, please remember to rate me 
-
Oct 17th, 2005, 04:24 PM
#2
Re: Detect a past event?
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
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|