How do I add to this code to prevent a runtime error when someone runs this code for the first time and doesn't have a folder named "Voya" in Outlook?
In other words, how can I automatically create a folder in outlook named "Voya" and setup a rule that automatically moves a daily email with a specific subject to that folder? Thanks a lot
Sub Voya_Open_Most_Recent_Email()
Dim OlApp As Object
Dim OlMail As Object
Dim OlItems As Object
Dim OlFolder As Object
Dim i As Long
Set at = Report_529.Voya_at
StartTime = Time
at = Dash(85)
at = at & vbCrLf & Space(2) & "VOYA Report" & Space(25) & "Date: " & ejDate & Space(10) & "Time: " & Time
at = at & vbCrLf & Dash(85)
If Err <> 429 Then
Set OlApp = CreateObject("Outlook.Application")
Else
Set OlApp = GetObject(, "Outlook.Application")
End If
Set OlFolder = OlApp.GetNamespace("MAPI").Folders(My_Email).Folders("Voya")
Set OlItems = OlFolder.Items
i = OlItems.Count
OlFolder.Items(i).Display
Set OlFolder = Nothing
Set OlItems = Nothing
Set OlMail = Nothing
Set OlApp = Nothing
End Sub
In other words, how can I automatically create a folder in outlook named "Voya" and setup a rule that automatically moves a daily email with a specific subject to that folder? Thanks a lot
Sub Voya_Open_Most_Recent_Email()
Dim OlApp As Object
Dim OlMail As Object
Dim OlItems As Object
Dim OlFolder As Object
Dim i As Long
Set at = Report_529.Voya_at
StartTime = Time
at = Dash(85)
at = at & vbCrLf & Space(2) & "VOYA Report" & Space(25) & "Date: " & ejDate & Space(10) & "Time: " & Time
at = at & vbCrLf & Dash(85)
If Err <> 429 Then
Set OlApp = CreateObject("Outlook.Application")
Else
Set OlApp = GetObject(, "Outlook.Application")
End If
Set OlFolder = OlApp.GetNamespace("MAPI").Folders(My_Email).Folders("Voya")
Set OlItems = OlFolder.Items
i = OlItems.Count
OlFolder.Items(i).Display
Set OlFolder = Nothing
Set OlItems = Nothing
Set OlMail = Nothing
Set OlApp = Nothing
End Sub