I have VBA code in an Outlook rule. I want when I get email with a specific subject, Outlook starts to run a script. However, when email is received, Outlook starts to run the code immediately picking up previous email, probably because the email was just received and not moved to a specific folder yet.
I tried
Application.Wait (Now + TimeValue("0:00:5"))
and
Outlook.Application.Wait (Now + TimeValue("0:00:5"))
just before grabbing the email with
Set oLookMailitem = Application.ActiveExplorer.CurrentFolder.Items("Apples Sales")
VBA shows an error
Object doesn't support this property or method
Here is the beginning of my code: The error occurs on Application.Wait (Now + TimeValue("0:00:5"))
.
Sub ExportOutlookTableToExcel()
Dim oLookInspector As Inspector
Dim oLookMailitem As MailItem
Dim oLookWordDoc As Word.Document
Dim oLookWordTbl As Word.Table
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlWrkSheet As Excel.Worksheet
Dim Today As String
Today = Date
Application.Wait (Now + TimeValue("0:00:5"))
'Grab Email Item
Set oLookMailitem =Application.ActiveExplorer.CurrentFolder.Items("Apples Sales")
Set oLookInspector = oLookMailitem.GetInspector
Set oLookWordDoc = oLookInspector.WordEditor