Outlook 2013 script to save email subject in an excel

Posted on 2014-08-05
Medium Priority
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 54

Accepted Solution

Rgonzo1971 earned 1500 total points
ID: 40243016

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


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
Mailbox Corruption is a nightmare every Exchange DBA wishes he never has. Recovering from it can be super-hectic if not entirely futile. And though techniques like the New-MailboxRepairRequest cmdlet have been designed to help with fixing minor corr…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses

864 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