Darrell Burns
dhb at flsi.com
Tue Aug 30 20:40:49 CDT 2011
Hey Bill, what is the ActiveExplorer? What reference do I need to set? -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of William Benson (VBACreations.Com) Sent: Tuesday, August 30, 2011 3:15 PM To: 'Access Developers discussion and problem solving' Subject: Re: [AccessD] Get sender's eMail address Make sure to set a reference to Outlook Sub test() Dim Exp As Explorer, Itm As Object Set Exp = ActiveExplorer On Error Resume Next For Each Itm In Exp.Selection Debug.Print GetFromAddress(Itm) Next End Sub Function GetFromAddress(objMsg) ' start CDO session Dim objSession As Object Dim strAddress As String Dim strEntryID As String Dim strStoreID As String Dim objCDOMsg As Object Set objSession = CreateObject("MAPI.Session") objSession.Logon "", "", False, False ' pass message to CDO strEntryID = objMsg.EntryID strStoreID = objMsg.Parent.StoreID Set objCDOMsg = objSession.GetMessage(strEntryID, strStoreID) ' get sender address On Error Resume Next strAddress = objCDOMsg.Sender.Address If Err = &H80070005 Then 'handle possible security patch error MsgBox "The Outlook E-mail and CDO Security Patches are " & _ "apparently installed on this machine. " & _ "You must response Yes to the prompt about " & _ "accessing e-mail addresses if you want to " & _ "get the From address.", vbExclamation, _ "GetFromAddress" End If GetFromAddress = strAddress Set objCDOMsg = Nothing objSession.Logoff Set objSession = Nothing End Function On 30 Aug 2011 at 14:11, Darrell Burns wrote: > Does anybody have any VBA code for getting the sender's email address? > I need this as the "from" argument for a mailitem object used in an > SMTP call. Thanx, Darrell > > -- > AccessD mailing list > AccessD at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/accessd > Website: http://www.databaseadvisors.com > -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com