I am having trouble adding in code to display a msgbox when a user inputs a variable text value into my inputbox that cannot be found. My code is looking for a outlook folder matching what the user entered into the inputbox (this value is variable) and if it doesn't find it, the vba will error out. I want it to display a msgbox saying folder was not found and loop until they enter a correct one.
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