Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to detect paste event in excel [duplicate]

Tags:

excel

vba

I need to detect paste command of excel. Is there any work around which can tell us when user click the paste on the menu pop up from the left mosue button click. This is required me to execute a procedure if user click the paste menu item. Any help would be appreciated.

Regards, Amit

like image 417
Amit Avatar asked Sep 21 '12 07:09

Amit


1 Answers

Borrowing from Excel VBA How to detect if something was pasted in a Worksheet. The Workbook_SheetChange event will fire for any change event on the page, including a paste.

From inside this event, you can then check if the last change was a paste by looking at the most recent entry in the Undo List History:

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
  Dim lastAction As String

  ' Get the last action performed by user
  lastAction = Application.CommandBars("Standard").Controls("&Undo").List(1)

  ' Check if the last action was a paste
  If Left(lastAction, 5) = "Paste" Then

    ' Do Stuff Here

  End If
End Sub
like image 198
KyleMit Avatar answered Oct 23 '22 07:10

KyleMit