I was running a Windows Task Scheduler task every morning to run a macro in an Excel file. My task didn't work because the VBA code is now giving me an error. The VBA code was 100% functional before today.
I get
"Object doesn't support this property or method"
Dim olApp As Object
Dim olNS As Object
Dim myDate As Date
Dim olItems As Object
Dim olItem As Object
Dim olAttach As Object
Dim Date1 As String
Dim Date2 As String
Dim iAttachments As Integer
Date1 = Date & " " & TimeValue("6:00:00")
Date2 = Date & " " & TimeValue("00:00:00")
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
Err.Clear: On Error GoTo 0
If olApp Is Nothing Then
Set olApp = CreateObject("Outlook.Application")
End If
Set olNS = olApp.GetNamespace("MAPI")
Set olItems = olNS.GetDefaultFolder(olFolderInbox).Items
For Each olItem In olItems
If olItem.ReceivedTime < Date1 Then '<----- ERROR LINE
If olItem.ReceivedTime > Date2 Then
If InStr(olItem.Body, "Darth Vader") > 0 Then
iAttachments = olItem.Attachments.Count + iAttachments
Set olAttach = olItem.Attachments.Item(1)
On Error GoTo Err_Handler
olAttach.SaveAsFile "C:\Desktop\Automatic Outlook Downloads" & "\" & olAttach.Filename
Set olAttach = Nothing
Set olItem = Nothing
If iAttachments = 4 Then Exit For
End If
End If
End If
Next
Set olAttach = Nothing
Set olItem = Nothing
Set olApp = Nothing
Set olNS = Nothing
Set olItems = Nothing
Exit Sub