Count of Email by Sender from Outlook folder

Is am new to writing VBA code , I would really really appreciate if anyone can help me with a VBA macro that can do the job of counting all emails by the sender's email address , within a particular Outlook folder.
If the count of emails from a particular sender is more than 1 , it should populate an excel sheet with data of the email adddress and the time of receipt of the mail from that sender .

It is not clear whether you want to process all the messages in the folder, or just those from a particular sender. The following does the latter.
The former would be rather more complicated if you want to record messages from senders that have sent more than one message. Recording all messages in a folder is much simpler.
Change the folder to the location where you want to store the workbook and
allow the macro to create that workbook.
Option Explicit
Private olNS As Outlook.NameSpace
Private olFolder As Outlook.MAPIFolder
Private olItems As Outlook.Items
Private olMsg As Outlook.MailItem
Private Count As Long
Private strDate As String
Private strTime As String
Private strFrom As String
Private strEmail As String
Private strSubject As String
Private strValues As String
Private vValues As Variant
Private ConnectionString As String
Private strSQL As String
Private CN As Object
Private xlApp As Object
Private xlWB As Object
Private bXLStarted As Boolean
Private nAttr As Long
Private i As Long
Private Const strTitles As String = "Date|Time|From|E-Mail"
Private Const strWorkbook As String = "C:\Path\Message Log.xlsx"
Sub MessageLog()
    Count = 0
    strFrom = InputBox("Enter sender's name to record." & vbCr & _
                       "Exact spelling is essential.")
    If strFrom = "" Then Exit Sub
    Set olNS = Outlook.GetNamespace("MAPI")
    Set olFolder = olNS.PickFolder
    Set olItems = olFolder.Items
    For Each olMsg In olItems
        'MsgBox olMsg.Sender & vbCr & strFrom
        If olMsg.Sender = strFrom Then
            Count = Count + 1
            If Count = 2 Then Exit For
        End If
    Next olMsg
    'MsgBox Count & vbCr & strFrom
    If Count > 1 Then
        MsgBox "A completion message will indicate when the process has finished."
        For Each olMsg In olItems
            If olMsg.Sender = strFrom Then
                RecordMessage olMsg
                DoEvents
            End If
        Next olMsg
    End If
    MsgBox "Process Complete."
lbl_Exit:
    Set olNS = Nothing
    Set olFolder = Nothing
    Set olItems = Nothing
    Set olMsg = Nothing
    Exit Sub
End Sub
Sub RecordMessage(Item As Outlook.MailItem)
    strFrom = Item.SenderName
    strEmail = Item.SenderEmailAddress
    strDate = Format(Item.ReceivedTime, "dd/MM/yyyy")
    strTime = Format(Item.ReceivedTime, "h:mm am/pm")
    strSubject = Item.Subject
    strValues = strDate & "', '" & _
                strTime & "', '" & _
                strFrom & "', '" & _
                strEmail
    If Not FileExists(strWorkbook) = True Then xlCreateBook strWorkbook:=strWorkbook, strTitles:=strTitles
    WriteToWorksheet strWorkbook:=strWorkbook, strRange:="Sheet1", strValues:=strValues
lbl_Exit:
    Exit Sub
End Sub
Private Function WriteToWorksheet(strWorkbook As String, _
                                  strRange As String, _
                                  strValues As String)
    ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
                       "Data Source=" & strWorkbook & ";" & _
                       "Extended Properties=""Excel 12.0 Xml;HDR=YES;"";"
    strSQL = "INSERT INTO [" & strRange & "$] VALUES('" & strValues & "')"
    Set CN = CreateObject("ADODB.Connection")
    Call CN.Open(ConnectionString)
    Call CN.Execute(strSQL, , 1 Or 128)
    CN.Close
    Set CN = Nothing
lbl_Exit:
    Exit Function
End Function
Private Sub xlCreateBook(strWorkbook As String, strTitles As String)
    vValues = Split(strTitles, "|")
    On Error Resume Next
    Set xlApp = GetObject(, "Excel.Application")
    If Err <> 0 Then
        Set xlApp = CreateObject("Excel.Application")
        bXLStarted = True
    End If
    On Error GoTo 0
    Set xlWB = xlApp.Workbooks.Add
    With xlWB.Sheets(1)
        For i = 0 To UBound(vValues)
            .Cells(1, i + 1) = vValues(i)
        Next i
    End With
    xlWB.SaveAs strWorkbook
    xlWB.Close 1
    If bXLStarted Then
        xlApp.Quit
        Set xlApp = Nothing
        Set xlWB = Nothing
    End If
lbl_Exit:
    Exit Sub
End Sub
Private Function FileExists(ByVal Filename As String) As Boolean
    On Error GoTo NoFile
    nAttr = GetAttr(Filename)
    If (nAttr And vbDirectory) <> vbDirectory Then
        FileExists = True
    End If
NoFile:
    Exit Function
End Function
Graham Mayor - Word MVP
www.gmayor.com

Similar Messages

  • Duplicate emails on BB when I send from Outlook

    I've got a client with a bunch of BBs, they use BIS and Exchange.  Whenever they send from Outlook, they get dupe emails on their phones.  I found a supposed solution, which was to go into BIS and recreate the accounts with OWA instead of IMAP, but no matter what URL I type in, it tells me it's invalid.  I also saw a possible solution that involved getting Exchange no to assign a new UID to the emails, but I'm not finding anything in Exchange to change that.  Any help would be very welcome.
    Thanks,
    Ben

    Hey Benny111,
    Welcome to the BlackBerry Support Community Forums.
    You're absolutely correct that you will need to integrate those IMAP accounts to POP3 or OWA to resolve this issue.
    Here is a link to a knowledge base article that will provide you more information:
    http://www.blackberry.com/btsc/KB13528 and look at cause #5.
    -ViciousFerret
    Come follow your BlackBerry Technical Team on Twitter! @BlackBerryHelp
    Be sure to click Like! for those who have helped you.
    Click  Accept as Solution for posts that have solved your issue(s)!

  • Why i couldn't open email that sent from Outlook?

                     Please help me for this matter, i had bought my BB Curve 8520 for just only 5 days and use latest firmware. I have setup 2 emails 1.) hotmail  2.) Outlook (Official mail) i found this issue after i had setup my office email for a few days.
                    Issue is when i open email that sent from Outlook (Official mail) that contained file .png or attached with file .png by using HTML  my bb couldn't open it, it will stuck but i can use any function but just the email that didn't open.
                    I ha contacted with my Local support, they inform me to do the hard reset, after i had hard reset it working fine with same email that couldn't open previously. After one day had past it has the same issue again.
    Please help me to fixed this issue, thank you in advance.
    P.S. I had never install any unauthorized program.

    Photoshop doesn't do anything special or different when a file is sent from an attachment. However, when you send an attachment from Outlook to Photoshop, that file is actually downloaded to your computer in a Temp folder before it is sent to Photoshop. Often times the permissions on this folder can be such that it prevents access. Other than that, all Outlook does is simply drop the file onto the Photoshop app file. The only thing that would involve Photoshop directly is if there are some damaged files involved with its connection to the rest of the system. If this is the case a reinstall would fix it. Otherwise, check the permissions on the Outlook temp folder (or at least the JPEG file it is trying to save).

  • Why can i not get my email to send from my mac? the outgoing server keeps saying its offline?!

    why can i not get my email to send from my mac? the outgoing server keeps saying its offline?! any help would be greatly appreciated

    markwmsn wrote:
    To each his own. I own Outlook, but I avoid using it like the plague. The only Mac mail software I have liked better than Apple's Mail was Qualcomm's Eudora, which is no longer updated or even available, won't run without Rosetta, and unfortunately never quite got the hang of IMAP.
    Check out this post regarding this user's continuing use of Eudora on his Lion MacBook:
    Shield Eudora from Lion's Claws
    A thousand thanks and kudos to Michael for this fabulously excellent thread!
    Eudora's now happy in her new Snow Leopard VM home on my Lion ModBook!
    Appears essential to keep resource-forked data off Lion disk:
    First attempt with Eudora on SL VM was sharing data on Lion disk. Error messages on open like "can't find Table of Contents" suggest Lion ate resource forks crucial to Eudora.
    Found success by transferring data from SL Mac to thumb drive, then mounted drive in SL VM so Lion couldn't touch.
    While Michael warns against storing data in VM, appears there's no choice with Eudora. At least She's enthroned on a mirrored RAID.
    There is Nothing like Eudora! (to tune of "There is Nothing Like a Dame" from South Pacific -- Oops! my gray hair is showing!)
    (It's amazing Parallels can force Lion to store taboo resource forks. Thank God for code warriors!)
    B
    http://forums.macrumors.com/showpost.php?p=16496788&postcount=355

  • How do I convert emails to PDF from Outlook to make a file on the PC?

    how do I convert emails to PDF from Outlook to make a file on the PC

    It is always tough for anyone when we need to save our emails into one file for future reference. You could either do it manually or can use a simple tool to Convert all your messages into one pdf file . This Single pdf file can be used if we need to read any past email. you can easily convert oulook to pdf in no time. If you are converting several email messages, you can either save them as separate files with initial layout fully intact or combine them into one big PDF document.

  • Replies to emails i send from my iMac are not downloading on my iPhone, why?

    Replies to emails i send from my iMac are not downloading on my iPhone, just my iMac. All other emails download to both devices. How can I get all emails to download on both devices?

    You may not have the same protocol setup. ie. Try using IMAP on both if available.
    What Mail account is it? @example.com

  • All of the emails i send from my iphone (mobile me) are blank.

    hi folks,
    all of the emails i send from my iphone (mobile me) are blank... i receive mail just fine.
    i can send using my mobile me account just fine from my macbook.
    my iphone is a 32gb 3GS on o2 ireland.
    i was using 3.1.2 and it never worked.
    today i upgraded to IOS 4... still no joy.
    deleted the account on the iphone and added it again.. still no joy.

    What Mac OS version is on the iMac?

  • Cant get emails to send from from ipad mini they just go to outbox and say there is a server error

    I cannot get my emails to send from my ipad mini (neither can orange), they just go to the outbox and say the server will not accept them.  I can receive them ok but not send them.  I have two accounts set up i cloud and orange, this is my main account.

    Double check your outgoing mail server.. settings - mail - account

  • Why do printed copies of emails I send from sub-ac...

    Hello, hoping someone can help.  I have a sub-account email address.  Sometimes if I send an email and the recipient prints it off, their hard copy prints the name of my primary account holder  (eg they expect to get an email from Jenny, and Joe's name is bizarrely printed at the top of the page).  There is no sign of the primary account holder's name on the screen, just on the printed version, where it appears like a page header - sitting a bit above the printed email they were expecting to see, which looks exactly the same as the on-screen version of the email, (eg it's 'from' my email address etc). Is there any way to make sure this doesn't happen?  It doesn't happen when everyone prints an email from me.
    Thanks

    when u use software like outlook etc. Make sure that will not delete emails from server when download them. There is option to choose auto deleting when download email. Some email provaider offer option to create the folder on server and u could move all downloaded email to HDD from email server to that folder and will stay on the server .
    Why move them from inbox to another folder beacuse some email clients will be downloading the same email from server. Usually in expensive email clients u can set to keep data on server and do not download again same emails.
    But sometimes this dont work and it will dont download new email better to set to download emails by date (24H day). Any new email from current day will be downloaded and oryginal version on server keeped on the server.
    Works in 99.9% emails. Why 99.9% when u dont use email account/client for more then 1-2 months the software may get bit confuse and dont copy all emails.
    ps: u can take out HDD, buy cheap HDD closure for 5GBP put that HDD in and connect via usb if HDD partions are not damaged u gonna be able to copy all data in very easy way . If partions are damaged/bad blocks etc the recovery of them is still possible but u will need some "skills" to pull out them, sometimes u can buy sam HDD for electronics beacuse old HDD has died and replace and copy data problems going up when head are down etc.
    U can still recover data by sending HDD to company which has special lab to do this. Must be impressive clean for opening HDD and accesing to discs and avoid any electro static bit on disc. expensive.. even very expensive depends of how much GB needs to be recovered.
    or buy online place on the server to make backup of pc. As the operator of server will make regulary backup of server so all your data will stay safe. Better the DVD disc, which u can lost or get damage, pendrive which  may die when using microwave etc.  U can alwayes use cabinet for dvds. But cabinet instead of case for disc. Will not get lost due to size and will be locked, use only DVD-R discs. Dont use xx-RW (rewritable discs) as u may overwrite data on disc by mystake.

  • How to transfer all emails and contacts from Outlook Express to Outlook 2010

    I have just done this and believe me it was a bit of a marathon! Microsoft tell you that you need to have both Outlook Express and Outlook 2010 running on the same machine. If, like me, your Outlook 2010 in running on a Windows 7 platform there is a problem.
    Until now I have been using Outlook Express on a Desktop running XP Pro. It has Outlook 2007 but it won’t run owing to a corrupted file. I set up my email account on an old XP laptop which has Outlook 2007. This is how I transferred emails between 2 machines
    running Outlook Express:
    After setting up the account (on the old laptop) I created sub-folders exactly the same as my existing account. Having got some emails in the inbox I made sure that each new sub-folder contained at least one random email simply by drag and drop. It seems to
    validate the folders. I then copied the folders from the maintenance directory on the desktop (you find this under Tools – Options – Maintenance) and pasted them into the equivalent folder on the this old laptop so they overwrote those present. I transferred
    the contacts simply using Export – Address Book using a csv file. I then set up the email account in Outlook 2007 on the old laptop and ran an import from Outlook Express which was fine as per Microsoft’s instructions. On that machine I then exported to a
    backup pst file which I transferred to my new Windows 7 machine and imported successfully into Outlook 2010. Perhaps there are easier ways but at least it worked!

    You can directly do the same, visit https://support.microsoft.com/en-us/kb/196215 to know the steps.

  • SAP Inbound email related query (from Outlook to SAP)

    Hi,
    I am in a situation where I have to send email from MS Outlook to SAP with a PDF file as an attachment. The PDF file will be stripped into an XML file and processed further and a reply is sent to the user sending the email. The Outlook admins have set up the necessary config for the connectivity - I am able to send the PDF file from Outlook to SAP (everything has been configured using SICF, SCOT etc) for inbound processing. In SCOT - Settings->Inbound processing I have used a Class which implements interface IF_INBOUND_EXIT_BCS (as per one of the blogs by Jeff Gebo). I can see the trace file in SCOT ->Utilities->Trace->Internal trace. When I send the PDF file, I can see in the trace (I cannot debug as the SAPCONNECT user which gets called in the backgound triggers the user exit class). In the trace file I can see my class gets instantiated but the next step to read the PDF file fails.  The code come the Jeff's blog which I use is as follows:
    Set return code so that no other Inbound Exist class will be called
    e_retcode = IF_INBOUND_EXIT_BCS=>gc_terminate.
    try.
    Get the email document that was sent.
      data: document type ref to if_document_bcs.
      document = io_sreq->get_document( ).
    Get the sender's address to reply back
      lv_sender = io_sreq->get_sender( ).
      addr = lv_sender->address_string( ).
      return_addr = addr.
    Get the interactive form attachment.
      data: pdf_table type BCSS_DBPC.
      pdf_table = document->get_body_part_content( 2 ).
    Convert the pdf table into an xstring.
      data: pdf_xstring type xstring,
            pdf_line type solix.
      clear pdf_xstring.
      loop at pdf_table-cont_hex into pdf_line.
        concatenate pdf_xstring pdf_line-line into pdf_xstring in byte mode.
      endloop.
    Process the PDF form
      data: formxml type string.
      formxml = me->process_form( pdf = pdf_xstring ).
    Here the contents of the pdf_table-cont_hex is blank (I used a table to populate the values). All I get in my Outlook inbox is a empty email with an empty subject from SAP (called by the instantiated class of the Interface)
    The irony is that I setup the same procedure has been configured and setup in another totally different SAP system and everything works fine there - I did a comparision of both SAP systems and everything seems fine (config wise and user exit class wise) and  everything is identical. I have no clue as to why it works in one system and not in the other system.
    If anyone has any pointers wit will be greatly appreciated as I am on a tight deadline - I have checked OSS but with no help.
    Thanks in advance,
    Ryan

    You may be able to find more information by putting an infinite loop at the beginning of your user exit:
    x = ' '.
    while x = ' '.
    x = ' '.
    endwhile.
    and then go into debugging via SM50 and set the x variable to break out of the loop.
    This technique is useful debugging workflows and other code which you cannot get to directly by placing a break-point.
    Andrew

  • Why isn't iCloud syncing emails I send from my various devices?

    I thought that iCloud was supposed to sync all emails sent from my desktop, my iPad, or my iPhone.  I don't see that a message that I send from my desktop is appearing on my iPad or iPhone.
    Is there a special setting I have missed in either iCloud or Mail
    Thanks,

    iCloud doesn't sync mail.  Whether or not sent email appears on your other devices depends on the type of email account you have, not on iCloud.  If you are using an IMAP account such as iCloud email, Gmail or Yahoo, or and Exchange account, you will seen any changes on one device (such as sending, deleting or moving email to a folder), reflected on all your other devices.  If you are using a POP/POP3 account you won't.  Sounds like you are using a POP account.  If so, you would need to switch to an IMAP or Exchange account in order to keep your email in "sync" across your devices.

  • Cannot Import Email and Folders from Outlook for Mac 2011

    After downloading Lion, I could not import emails and folder structure from Outlook for Mac 2011.

    You're in luck, Imap and Exchange accounts store their data on the server.
    Leave Outlook alone, just add the accounts to Mail and let them synchronize, no import required. You can leave them in Outlook or remove them as you please once everything in Mail is done.

  • Why will IMAP email not send from Mac OS 10.10.1 Yosemite Mail even though it is configured the same as on my old Macbook (and emails are sending just fine on the old computer)?

    I can receive but cannot send IMAP email on my 1&1 mail account from Mac OS 10.10.1 Yosemite Mail on my new Macbook Pro. The account is set up the same port, password, username, server name as on my old Macbook and emails are sending just fine on the old computer.
    When I hit send on the new Macbook Pro running Yosemite I get this message:
    "The connection to host ... on port 993 failed.
    Select a different outgoing mail server from the list below or click Try Later to leave the message in your Outbox until it can be sent."
    It shows the server as (offline)
    I've tried erasing and typing in the password.  I've tried both checking and unchecking Automatically detect and maintain account settings. Still cannot send.
    I also have a Gmail account and it is working...

    email service uses an Incoming Server and an Outgoing Server. Mac Mail makes access to the Incoming Server(s) obvious, and hides the settings for the outgoing Server(s). A quick and easy way to get access to the Outgoing Servewr settings is to use:
    Window > Connection Doctor ...
    ... then click on the red light for the Server that is not working for you to see its settings.
    This web page will make an educated guess about how to set up your Servers, and NO SPAM will follow:
    https://www.apple.com/support/mail-settings-lookup/

  • When I open an email's attachment from Outlook, the email's attachment is no longer avail to open on my iPad and iPhone

    When opening an email's attachment in Outlook 2007, that email's attachment is no longer available to view on my iPhone and iPad.
    How do I correct this to keep the attachment available on iPad and iPhone, when the email's attachment is initially opened from Microsoft Outlook please??

    If you're talking about an old iCloud ID, you have to delete the old account, provide the password for the old ID when prompted to turn off Find My iPhone, then sign back in with the ID you wish to use.  If you don't know the password for your old ID, or if it isn't accepted, go to https//appleid.apple.com, click Manage my Apple ID and sign in with your current iCloud ID.  Tap edit next to the primary email account, tap Edit, change it back to your old email address and save the change.  Then edit the name of the account to change it back to your old email address.  You can now use your current password to turn off Find My iPhone on your device, even though it prompts you for the password for your old account ID. Then go to Settings>iCloud, tap Delete Account and choose Delete from My iDevice when prompted (your iCloud data will still be in iCloud).  Next, go back to https//appleid.apple.com and change your primary email address and iCloud ID name back to the way it was.  Now you can go to Settings>iCloud and sign in with your current iCloud ID and password.

Maybe you are looking for

  • Sales order wise report

    HI friends I am generating a report according to sales order wise stock . I need a help in these kdauf             kdpos      shkzg        menge           0000001663     000010     S           10 0000001663     000010     S           20 0000001663  0

  • Can we call a simple java application from ESB

    Please let me know how this can be done by using a ESB. The application jar exists on the host server. How we can pass parameters etc and receive results from this application. Any help will be greatly appreciated. Prakash

  • Why does  my photo look posterized when I open it in CS6?

    When opening a picture in CS6, either from Bridge or just from File, open in CS6, they have this 60's posterized look on most of the picture. Settings are 8 bit, RGB, haven't changed any settings and even reinstalled CS6 over the old CS6, but still d

  • WD Elements can*t be integrated into Active Directory

    Hope this is the right place to put this question in: Lately I was buying a WD Myclouds DL4100. We installed everything andtried to put it into our active directory. We made sure we typedeverything in correctly and where it belongs to because the man

  • Alert's for Multiple Planning Book

    Hello Experts,           We have created a macro, let's say for planning book1. Created a activity for the same. So once the job is executed we are able to see the alerts. Now the requirement is the same alerts has to be viewed in other planning book