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
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
Display()
Else
MsgBox("Could not load EMail message into database.")
End If
Else
MsgBox("Clipboard content is not an email message")
End If
Else
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
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)
Else
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.