Sub GetEmailSender() ' ------------------------------------------------ ' --- You may use and/or change this code freely ' --- provided you keep this message ' --- ' --- Description: ' --- Extracts email sender ' --- Runs on all mailitems in current folder that ' --- are unread ' --- ' --- By Max Flodén 2006 - http://www.tjitjing.com ' ------------------------------------------------ Dim myOlApp As New Outlook.Application Dim myNameSpace As Outlook.NameSpace Dim mySelection As Selection Dim myItem As Object Dim myMailItemLog As Outlook.MailItem Dim myFolder As Outlook.MAPIFolder Dim strContactFolderName As String 'Directly under Public Folders\All Public Folders Dim strNewsletterCategoryName As String Dim strMailItemSender As String Dim strMailTo As String Dim intMessageCount As Integer Dim bolDebug As Boolean 'If true error messages will be shown Dim strTemp As String Set myNameSpace = myOlApp.GetNamespace("MAPI") 'Debug settings bolDebug = True 'Ask to continue - start warning intRes = MsgBox("This macro will go thru all items in folder." & vbCrLf & "Would like to continue?", vbYesNo + vbQuestion, "Get Email Sender") If Not intRes = vbYes Then Exit Sub 'Create a new email to use as log file Set myMailItemLog = myOlApp.CreateItem(olMailItem) myMailItemLog.Recipients.Add (myNameSpace.CurrentUser) myMailItemLog.Subject = "Email from Body - " & Now() myMailItemLog.BodyFormat = olFormatPlain myMailItemLog.Body = Now() & " Starting..." & vbCrLf & vbCrLf 'Go thru all items in folder intMessageCount = 0 intMsgCount_Error = 0 For Each myItem In myOlApp.ActiveExplorer.CurrentFolder.Items If Not TypeName(myItem) = "MailItem" Then 'Errorlog If bolDebug Then myMailItemLog.Body = myMailItemLog.Body & "ERROR - MESSAGE TYPE IS NOT MAILITEM." & vbCrLf myItem.UnRead = True intMsgCount_Error = intMsgCount_Error + 1 ElseIf myItem.UnRead Then myMailItemLog.Body = myMailItemLog.Body & myItem.SenderEmailAddress & vbCrLf myItem.UnRead = False myItem.FlagStatus = olFlagMarked intMessageCount = intMessageCount + 1 End If Next 'Done - write to log and show done message myMailItemLog.Body = myMailItemLog.Body & vbCrLf & Now() & " Done. Email addresses extracted: " & intMessageCount & ". Email addresses NOT extracted: " & intMsgCount_Error & "." myMailItemLog.Display MsgBox Now() & " Done. Email addresses extracted: " & intMessageCount & ". Email addresses NOT extracted: " & intMsgCount_Error & ".", vbInformation, "Done" End Sub