BeforeItemPaste Event

Occurs when a Microsoft Outlook item is pasted. This event can be cancelled after it has started.

Private Subexpression_BeforeItemPaste(ClipboardContent As Variant, ByVal Target As MAPIFolder, Cancel As Boolean)

*expression   * An expression that returns an **Explorer**object declared with events in a class module.

*ClipboardContent    * Required Variant. The content to be pasted.

*Target   * Required MAPIFolder. The destination of the paste.

*Cancel   * Required Boolean. False when the event occurs. If the event procedure sets this argument to True, the operation is not completed and the item is not deleted.

Example

The following Microsoft Visual Basic/Visual Basic for Applications (VBA) example prompts the user before pasting the contents of the Clipboard to the specified target. If the user clicks Yes, the current content in the Clipboard is copied to the specified target destination. The sample code must be placed in a class module such as ThisOutlookSession, and the Initialize_handler routine must be called before the event procedure can be called by Outlook.

Public WithEvents myOlExp As Outlook.Explorer

Sub Initalize_Handler()
    Set myOlExp = Application.ActiveExplorer
End Sub

Private Sub myOlExp_BeforeItemPaste(ClipboardContent As Variant, ByVal Target As MAPIFolder, Cancel As Boolean)
    Dim lngAns As Integer 'users' answer
    'Prompt user about paste
    lngAns = MsgBox("Are you sure you want to paste the contents of the clipboard into the " _
                    & Target.Name & "?", vbYesNo)
    If lngAns = vbNo Then
        Cancel = True
    End If
End Sub

Applies to | Explorer Object

See Also | BeforeDelete Event | BeforeItemCopy Event | BeforeItemCut Event | BeforeMaximize Event | BeforeMinimize Event | BeforeMove Event | BeforeSize Event