title: VBA Try and Catch (MS Outlook)
body: <p>I use the following function to monitor a public Outlook folder for new E-Mails to arrive:</p>
  
  <pre><code>Public Sub Application_Startup()
  
     Set NewMail = Application.GetNamespace("MAPI").Folders(3).Folders(2)....
  
  End Sub
  </code></pre>
  
  <p>For some reason, the path to this public folder changes over time in a weekly period. What changes is the number in <code>.Folders(3)</code>. 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:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Since I am new to VBA I am struggeling implementing this Try and Catch function. Can anyone assist with VBA code in Outlook?</p>
  
  <p>I think one solution I just manage to implement is:</p>
  
  <pre><code>For i = 1 To 3
  
      On Error Resume Next
  
      Set NewMail = Application.GetNamespace("MAPI").Folders(i).Folders(2)....
  
  Next i
  </code></pre>