I use the following function to monitor a public Outlook folder for new E-Mails to arrive:
Public Sub Application_Startup()
Set NewMail = Application.GetNamespace("MAPI").Folders(3).Folders(2)....
End Sub
For some reason, the path to this public folder changes over time in a weekly period. What changes is the number in .Folders(3)
. It varies from 1 to 3.
Apparently, to keep the function working and to catch the error, when the path changes, I want to implement a try and catch function such as:
Try {
Set NewMail = Application.GetNamespace("MAPI").Folders(1).Folders(2)....
Catch Error
Try {
Set NewMail = Application.GetNamespace("MAPI").Folders(2).Folders(2)....
Catch Error
Try {
Set NewMail = Application.GetNamespace("MAPI").Folders(2).Folders(2)....
Catch Error
Since I am new to VBA I am struggeling implementing this Try and Catch function. Can anyone assist with VBA code in Outlook?
I think one solution I just manage to implement is:
For i = 1 To 3
On Error Resume Next
Set NewMail = Application.GetNamespace("MAPI").Folders(i).Folders(2)....
Next i