Results 1 to 2 of 2

Thread: Detect a past event?

  1. #1

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    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

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    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:
    1. Private Sub Worksheet_Change(ByVal Target As Range)
    2. Dim MyObj As DataObject
    3. Dim PasteVal As String
    4.  
    5.     Set MyObj = New DataObject
    6.     MyObj.GetFromClipboard
    7.     PasteVal = MyObj.GetText(1)
    8.     If Target.Text = PasteVal Then
    9.         'insert code here
    10.     End If
    11. 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
  •  



Click Here to Expand Forum to Full Width