title: VBA: Collecting and showing error messages in UserForm?
body: <p>I have written some code in VBA that gets data from other workbooks and then updates several "masterfiles", through which my code loops. Right now I make a backup before updating the data and at the end of the loop I save the updated file. The code works and I'm not sure how pertinent it even is to the question:</p>
  
  <pre><code>Sub YearlyReport()
  
  Dim FilePath As String
  Dim VWArray As Variant
  Dim wbVWAggr As Workbook
  Dim VWNumber As Variant
  
  FilePath = "C:\VBA\YearlyReport\"
  VWArray = Array(21, 25, 35, 45, 46, 49, 51, 52, 53, 54, 101)
  
  Application.ScreenUpdating = False
      For Each VWNumber In VWArray
          Set wbVWAggr = Application.Workbooks.Open(FilePath &amp; "Report" &amp; VWNumber &amp; ".xlsx")
          wbVWAggr.SaveAs FilePath &amp; "Report" &amp; VWNumber &amp; "_old" &amp; Format(Now(), "dd-mm-yyyy hh-mm-ss") &amp; ".xlsx"
  
          'Data gets copy pasted from other workbooks
  
          Application.DisplayAlerts = False 'Overwrite old file
          wbVWAggr.SaveAs FilePath &amp; "Report" &amp; VWNumber &amp; ".xlsx"
          Application.DisplayAlerts = True
      Next VWNumber
  
  Application.ScreenUpdating = True   
  End Sub
  </code></pre>
  
  <p>This approach is fine, but what if a file can't be found? What I really wanna do is to continue the code, collect the error messages and show them to the user at the end (I put the code in a separate sub). I'd still have to write it, but I could then ask the user if he wants to save or cancel the whole thing: </p>
  
  <pre><code>Sub ErrorCollection()
      Dim ErrorCount As Long
      Dim ErrorArray() As String
      Dim FilePath As String
      Dim VWNumber As Variant
      Dim VWArray As Variant
      Dim ErrorMessage As String
      Dim Item As Variant
  
      FilePath = "C:\VBA\YearlyReport\"
      VWArray = Array(21, 25, 35, 45, 46, 49, 51, 52, 53, 54, 101)
  
      For Each VWNumber In VWArray
          If Dir$(FilePath &amp; "Report" &amp; VWNumber &amp; ".xlsx") = "" Then
              ErrorMessage = "Report" &amp; VWNumber &amp; " cannot be found."
              ReDim Preserve ErrorArray(ErrorCount)
              ErrorArray(ErrorCount) = ErrorMessage
              ErrorCount = ErrorCount + 1
          End If
      Next VWNumber
  
      If ErrorCount &gt; 0 Then
          MsgBox Join(ErrorArray, vbCrLf)
      End If
  End Sub
  </code></pre>
  
  <p>Ideally the user can also hide the popup message to look at the files, which means using a UserForm - but in that case how do I show the error messages like in the MsgBox? I tried googling, but I only came across questions how to populate an array from a userform. </p>