Click here to Skip to main content
15,614,270 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to enable my application to be able to past an outlook message into the application data. Not the text of the message, the actual message. That is, copy the message file to a specified directory with a new name and store this file name as part of the application data.

Specifically, I want the user the be able to copy a file into the clipboard while outlook is running, and then paste it into the data field on the specific form.
I have been able to do this from the normal windows clipboard, but do not seem to be able to do this with an outlook message.

This sub works for a windows clipboard dataobject:

Private Sub Paste_Clipboard(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pmnuPasteEMailMessage.Click
    'paste the contents of the windows clipboard into the database
    Dim iData As IDataObject = Clipboard.GetDataObject()
    Dim tstr() As String = iData.GetData(DataFormats.FileDrop)
    If tstr IsNot Nothing Then
        Dim iFileName As String = tstr(0)
        Dim iFlExt As String = FileExt(iFileName)
        If iFlExt = "msg" Then
            If ShippingCL.PasteEMailMessage(iFileName) = True Then
                MsgBox("Could not load EMail message into database.")
            End If
            MsgBox("Clipboard content is not an email message")
        End If
        'If it's not a file
        MsgBox("Data in the clipboard is not a file")
    End If
End Sub

I can't seem to be able to get the following sub to get an outlook message object:

Private Sub Paste_FromOutlook(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pmnuPasteEMailMessage.Click
    Dim iData As IDataObject = Clipboard.GetDataObject()
    If IsProcessRunning("Outlook") = False Then ' make sure outlook is running
        MsgBox("Outlook is not running")
        Exit Sub
    End If
    If iData.GetDataPresent(DataFormats.FileDrop) = False Then Exit Sub
    Dim mOL As Outlook.Application = GetObject(, "Outlook.Application")
    Dim oMsg As Outlook.MailItem = iData.GetData(DataFormats.FileDrop)
    If oMsg IsNot Nothing Then
        MsgBox("Received by: " & oMsg.ReceivedByName)
        MsgBox("Outlook clipboard is empty")
    End If
End Sub

How do I get an outlook message from the clipboard?

What I have tried:

Reviewed numerous articles and posts on CodeProject and elsewhere on the web to determine how the Outlook dataobject model functions.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900