IndigoDragon
Programmer
Hello,
I've been trying to set up a CDO connection to retrieve the senders mail address. The script returns a 'user-defined type not defined' error for the "MAPI" statement. I've added a reference to the "Outlook 10.0 Object Library". The code I used initially I got from MSDevNetwork (MSDN.com) and should work for Office 2002 (Which I'm using.). Here's the code:
Sub GetSender()
' *****************************************
' Get the senders e-mail address using CDO.
' *****************************************
Dim objCDO As MAPI.Session
Dim objMsg As MAPI.Message
Dim objSender As MAPI.AddressEntry
Dim oMsg As Outlook.MailItem
Dim strMsg As String
On Error Resume Next
Set oMsg = Application.ActiveExplorer.Selection.Item(1)
Set objCDO = CreateObject("MAPI.Session")
objCDO.Logon "", "", False, False
Set objMsg = objCDO.GetMessage(oMsg.EntryID)
Set objSender = objMsg.Sender
strMsg = "Subject: " & objMsg.Subject & vbCrLf _
& "Sender Name: " & objSender.Name & vbCrLf _
& "Sender e-mail: " & objSender.Address & vbCrLf _
& "Sender type: " & objSender.Type
MsgBox strMsg, vbInformation
End Sub
-----------------------------------------------------------
Does anyone know what the problem is?
ThanX!
I've been trying to set up a CDO connection to retrieve the senders mail address. The script returns a 'user-defined type not defined' error for the "MAPI" statement. I've added a reference to the "Outlook 10.0 Object Library". The code I used initially I got from MSDevNetwork (MSDN.com) and should work for Office 2002 (Which I'm using.). Here's the code:
Sub GetSender()
' *****************************************
' Get the senders e-mail address using CDO.
' *****************************************
Dim objCDO As MAPI.Session
Dim objMsg As MAPI.Message
Dim objSender As MAPI.AddressEntry
Dim oMsg As Outlook.MailItem
Dim strMsg As String
On Error Resume Next
Set oMsg = Application.ActiveExplorer.Selection.Item(1)
Set objCDO = CreateObject("MAPI.Session")
objCDO.Logon "", "", False, False
Set objMsg = objCDO.GetMessage(oMsg.EntryID)
Set objSender = objMsg.Sender
strMsg = "Subject: " & objMsg.Subject & vbCrLf _
& "Sender Name: " & objSender.Name & vbCrLf _
& "Sender e-mail: " & objSender.Address & vbCrLf _
& "Sender type: " & objSender.Type
MsgBox strMsg, vbInformation
End Sub
-----------------------------------------------------------
Does anyone know what the problem is?
ThanX!