• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Sent items from Outlook goes to excel after sending it.

joms

New Member
Hi Everyone,

I'm currently using extract method to get my sent mail from the sent items from outlook going to excel on a weekly basis.
Just want to ask if there's a way that "After clicking Send button in outlook it will automatically goes to my target excel file in this format:
- Subject
-Body
-Sent to
-Date
So that i can track my actions/sent mails on a daily basis.

Thank you in advance.
 
Prefer everything explained here
https://www.extendoffice.com/documents/outlook/5455-outlook-auto-export-emails-to-excel.html
this code put in ThisOutlookSession
Code:
Public WithEvents GMailItems As Outlook.Items
Private Sub Application_Startup()
    Set GMailItems = Outlook.Application.Session.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub GMailItems_ItemAdd(ByVal Item As Object)
    Dim xMailItem As Outlook.MailItem
    Dim xExcelFile As String
    Dim xExcelApp As Excel.Application
    Dim xWb As Excel.Workbook
    Dim xWs As Excel.Worksheet
    Dim xNextEmptyRow As Integer
    On Error Resume Next
    If Item.Class <> olMail Then Exit Sub
    Set xMailItem = Item
    xExcelFile = "C:\Users\DT168\Desktop\split document\kto-data.xlsx"
    If IsWorkBookOpen(xExcelFile) = True Then
        Set xExcelApp = GetObject(, "Excel.Application")
        Set xWb = GetObject(xExcelFile)
        If Not xWb Is Nothing Then xWb.Close True
    Else
        Set xExcelApp = New Excel.Application
    End If
    Set xWb = xExcelApp.Workbooks.Open(xExcelFile)
    Set xWs = xWb.Sheets(1)
    xNextEmptyRow = xWs.Range("B" & xWs.Rows.Count).End(xlUp).Row + 1
    With xWs
        .Cells(xNextEmptyRow, 1) = xNextEmptyRow - 1
        .Cells(xNextEmptyRow, 2) = xMailItem.SenderName
        .Cells(xNextEmptyRow, 3) = xMailItem.SenderEmailAddress
        .Cells(xNextEmptyRow, 4) = xMailItem.Subject
        .Cells(xNextEmptyRow, 5) = xMailItem.ReceivedTime
    End With
    xWs.Columns("A:E").AutoFit
    xWb.Save
End Sub
Function IsWorkBookOpen(FileName As String)
    Dim xFreeFile As Long, xErrNo As Long
    On Error Resume Next
    xFreeFile = FreeFile()
    Open FileName For Input Lock Read As #xFreeFile
    Close xFreeFile
    xErrNo = Err
    On Error GoTo 0
    Select Case xErrNo
        Case 0: IsWorkBookOpen = False
        Case 70: IsWorkBookOpen = True
        Case Else: Error xErrNo
    End Select
End Function
NO.Sender NameSender Email AddressSubjectReceived Time
 
Back
Top