title: Excel crashes after SaveAs
body: <p>I have inherited an excel project, which I’ve been tasked to automate and develop further.</p>
  
  <p>Use case being  </p>
  
  <ul>
  <li>An order comes in</li>
  <li>User opens the base (root) excel file </li>
  <li>Types in the relevant info (customer, order, data, tasks, etc) </li>
  <li>And saves the new task file in a folder with tasks in progress </li>
  <li>Leaving the base (root) excel basic and ready for next order.  </li>
  </ul>
  
  <p>The new task file needs to have a certain file name structure, which has been sorted.</p>
  
  <p>My problem comes in on <code>ActiveWorkbook.SaveAs filename</code>.</p>
  
  <p>As I step through <kbd>F5</kbd> the lines, it goes through all the steps, creates the filename, shows the Save As UI, correctly shows the right folder and suggested filename, and actually saves the file. As I come out of ErrHandler and the last <code>Application.EnableEvents = yes</code> - it crashes. It seems to either be closing the base file, opening the new, or transfer active workbook to the new save file.</p>
  
  <p>Which is fine, if it could stop crashing.</p>
  
  <pre><code>If criticalInput then
      Msgbox “U been bad, U Shall not PASS!”, vbCritical ‘Not actual text or box showing, just for demo.
  Else
      Dim fileSaveName As Variant
  
      '### It Crashes after saving (possible at opening)
      fileSaveName = Application.GetSaveAsFilename( _
      InitialFileName:=tasksfolder &amp; "\" &amp; suggestFilename, _
      fileFilter:="Excel-projectmappe med aktive makroer (*.xlsm), *.xlsm")
  
      If fileSaveName &lt;&gt; False Then
          '### here is where you would save your file
          DoEvents ‘ Debugging research tells this should be here. Not that is changes anything.
          ActiveWorkbook.SaveAs fileSaveName ‘ During dev this has been disabled.
      End If ' SaveAs
  End If ' criticalInput
  
  ErrHandler:
      '## Reset back to default
      Application.DefaultFilePath = strDefault
  
      Application.EnableEvents = True
  End Sub
  </code></pre>
  
  <p>Debugging  </p>
  
  <ul>
  <li>I can save the file just nicely, if I disable SaveAs and work only on the base (root) excel file. </li>
  <li>I can open the new task file and save it nicely. (Just being a bugger about overwriting, Y/N)  </li>
  <li>Debugging research said I needed a DoEvents prior to SaveAs  </li>
  <li>Debugging research also said only to have the most relevant references present (in my case unselect OLE Automation)  </li>
  <li>During debugging, I’ve also created, AfterSave() and Open(). They triggers normally during normal operation, but fails when SaveAs has crashed. Eg as I disable SaveAs or when I open the excel book normally.</li>
  </ul>
  
  <pre><code>Private Sub Workbook_AfterSave(ByVal Success As Boolean)
      On Error GoTo ErrHandler    
      If Success Then
          Application.EnableEvents = False
          'MsgBox "Success save", vbInformation ' for debugging purposes.
      End If    
      ErrHandler:
      Application.EnableEvents = True
  End Sub
  
  Private Sub Workbook_Open()
      'MsgBox "I haz been opened, yehawww", vbInformation ' debugging
  End Sub
  </code></pre>