Outlook 2013 script to save email subject in an excel

Posted on 2014-08-05
Last Modified: 2014-12-04
Hi team

How can I create an Outlook 2013 script to run as rule in order to save in an excel file all the email subjects received.
And also, how can I add the date even?

Kind regards
Question by:acunaara
    1 Comment
    LVL 47

    Accepted Solution


    you could try to insert a similar code in the ThisOutlookSession module of Outlook

    Private WithEvents Items As Outlook.Items
    Private Sub Application_Startup()
      Dim olApp As Outlook.Application
      Dim objNS As Outlook.Namespace
      Set olApp = Outlook.Application
      Set objNS = olApp.GetNamespace("MAPI")
      ' default local Inbox
      Set Items = objNS.GetDefaultFolder(olFolderInbox).Items
    End Sub
    Private Sub Items_ItemAdd(ByVal item As Object)
      Dim xlApp As Object
      On Error GoTo ErrorHandler
      Dim Msg As Outlook.MailItem
      If TypeName(item) = "MailItem" Then
        Set Msg = item
        Set xlApp = CreateObject("Excel.Application")
        With xlApp
            .Visible = True
            .EnableEvents = True
        End With
        strFile = "c:\Documents\Book991.xlsx"  'Put your file path.
        Set destWb = xlApp.Workbooks.Open(strFile)
        Set destWs = destWb.Worksheets("Log sheet")
        destWs.Range("A" & Rows.Count).End(xlUp).Offset(1) = Msg.ReceivedTime
        destWs.Range("A" & Rows.Count).End(xlUp).Offset(0, 1) = Msg.Subject
        destWb.Close True
        Set destWs = Nothing
        Set destWb = Nothing
        Set xlApp = Nothing
      End If
    Set Msg = Nothing
      Exit Sub
      MsgBox Err.Number & " - " & Err.Description
      Resume ProgramExit
    End Sub

    Open in new window


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Email signatures have numerous marketing benefits. Here are 8 top reasons to turn your email signature into a marketing channel.
    Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now