My input box fills the inboxfldr in this code Set Fldr = olNs.GetDefaultFolder(olFolderInbox).Folders(inboxfldr). If the object isn't found the vba gives a run time error. I want to suppress that error, prompt a message box that folder isn't found and just re-promt my inputbox. Looking for some help.
Code:
Sub GetFromInbox()
Dim olApp As Outlook.Application
Dim olNs As Namespace
Dim Fldr As MAPIFolder
Dim olMail As Variant
Dim DateCount As Integer
Dim myDate1 As Date
Dim myDate2 As Date
Dim item As Object
Dim doClip As MSForms.DataObject
Dim xlApp As Object ' Excel.Application
Dim xlWkb As Object
inboxfldr = InputBox("Enter Outlook Folder Name", "Inbox Alert Folder")
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox).Folders(inboxfldr)
Set doClip = New MSForms.DataObject
x = Date
myDate1 = Sheets("Inbox Alerts").Range("A1").Value
myDate2 = Sheets("Inbox Alerts").Range("B1").Value
For Each olMail In Fldr.Items
If DateSerial(Year(olMail.ReceivedTime), Month(olMail.ReceivedTime), Day(olMail.ReceivedTime)) >= myDate1 And _
DateSerial(Year(olMail.ReceivedTime), Month(olMail.ReceivedTime), Day(olMail.ReceivedTime)) <= myDate2 And _
InStr(olMail.Subject, "Alert") >= 0 _
Then
doClip.SetText olMail.Body
doClip.PutInClipboard
Sheets("Inbox Alerts").Cells(Rows.count, 1).End(xlUp).Offset(1, 0).PasteSpecial "Text"
DateCount = DateCount + 1
End If
Next olMail
Set Fldr = Nothing
Set olNs = Nothing
Set olApp = Nothing
End Sub