?
Solved

Excel VBA - determine whether an Outlook message displayed is actually sent

Posted on 2014-04-07
6
Medium Priority
?
2,337 Views
Last Modified: 2014-04-07
Hi. I have an Outlook message declared as follows in Excel VBA. It then is displayed in the second line. How do I determine if the message is actually sent?
Dim Msg As Outlook.MailItem
Msg.Disply
0
Comment
Question by:Murray Brown
  • 4
  • 2
6 Comments
 
LVL 28

Expert Comment

by:MacroShadow
ID: 39984122
Look in the sent items.

If you want to send it use
Msg.Send and not Msg.Display (note you have a typo).
0
 

Author Comment

by:Murray Brown
ID: 39984136
Hi. Thanks, I am actually looking to detect programmatically whether the email was sent. Sorry for not explaining that clearly
I saw this link but am not sure how to implement it
http://stackoverflow.com/questions/2533066/vba-outlook-mail-display-recording-when-if-sent-manually
0
 
LVL 28

Expert Comment

by:MacroShadow
ID: 39984144
Here is a sample that will loop thru an Outlook folder:
Sub Download_Outlook_Mail_To_Excel()
    'Add Tools->References->"Microsoft Outlook nn.n Object Library"
    'nn.n varies as per our Outlook Installation
    Dim Folder As Outlook.MAPIFolder
    Dim iRow As Integer
 
    'Mailbox or PST Main Folder Name (As how it is displayed in your Outlook Session)
    MailBoxName = "MailBox Name"
 
    'Mailbox Folder or PST Folder Name (As how it is displayed in your Outlook Session)
    Pst_Folder_Name = "Folder Name" 'Sample "Inbox" or "Sent Items"
 
    Set Folder = Outlook.Session.Folders(MailBoxName).Folders(Pst_Folder_Name)
    If Folder = "" Then
        MsgBox "Invalid Data in Input"
        GoTo end_lbl1:
    End If
 
    'Rad Through each Mail and export the details to Excel
    Sheets(1).Activate
    Folder.Items.Sort "Received"
    For iRow = 1 To Folder.Items.Count
        Sheets(1).Cells(iRow, 1).Select
        Sheets(1).Cells(iRow, 1) = Folder.Items.Item(iRow).SenderName
        Sheets(1).Cells(iRow, 2) = Folder.Items.Item(iRow).Subject
        Sheets(1).Cells(iRow, 3) = Folder.Items.Item(iRow).ReceivedTime
        Sheets(1).Cells(iRow, 4) = Folder.Items.Item(iRow).Size
        'Sheets(1).Cells(iRow, 5) = Folder.Items.Item(iRow).SenderEmailAddress
        'Sheets(1).Cells(iRow, 6) = Folder.Items.Item(iRow).Body
    Next iRow
    MsgBox "Outlook Mails Extracted to Excel"
 
end_lbl1:
 
End Sub

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 28

Accepted Solution

by:
MacroShadow earned 2000 total points
ID: 39984159
Cool!

1. Add a reference to outlook
2. Create a class module, name it EmailWatcher
3. Copy this code to the class:
Public BoolRange As Range
Public DateRange As Range
Public WithEvents TheMail As Outlook.MailItem


Private Sub TheMail_Send(Cancel As Boolean)
    If Not BoolRange Is Nothing Then
        BoolRange.Value = True
    End If
    If Not DateRange Is Nothing Then
        DateRange.Value = Now()
    End If
End Sub

Open in new window

4. Here is a sample usage:
With oMail
    .To = addr
    .Subject = "CCAT eVSM Utilities License Code"
    .Body = "Message body"
    .Display
End With
Set CurrWatcher = New EmailWatcher
Set CurrWatcher.BoolRange = Range("G12")
Set CurrWatcher.TheMail = oMail

Open in new window

Range G12 will tell you when it was sent
0
 

Author Closing Comment

by:Murray Brown
ID: 39984198
Thank you very much for taking all the time out to show me. Much appreciated!
0
 
LVL 28

Expert Comment

by:MacroShadow
ID: 39984205
My pleasure!
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

This article lists the top 5 trialware OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their Exchange server is no longer available or other critical issues with Exchange server or impo…
There can be many situations demanding the conversion of Outlook OST files to PST format and as such, there is no shortage of automated tools to perform this conversion. However, what makes Stellar OST to PST converter stand above the rest? Let us e…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?

850 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