title: Run subroutine when Workbook finishes loading?
body: <p><strong>Scope</strong></p>
  
  <p>I am working on automatically generating some Excel reports via C#. The problem is that, when it comes to "Features", my support library <a href="http://epplus.codeplex.com/" rel="nofollow noreferrer">EPPlus</a> doesn't cover it all.</p>
  
  <p><strong>Solution</strong></p>
  
  <p>Since i know that VBA has support for everything i need to do on Excel Files, i decided to use it in order to accomplish everything i can't in C#. So here's my current flow for generating the report</p>
  
  <p>1 - Setup a "Template" excel file (containing all the VBA code i need, configured into the <code>Workbook_Open</code> event, so that they will run as soon as the person opens the excel document)</p>
  
  <p>2 - Run my C# code to open the template, fill it with data, generate pivot tables, charts and so forth</p>
  
  <p>3 - Save it with a different name, to avoid overriding the Template file</p>
  
  <p>By doing so, i end up having a report that is ready to "Trigger" my macro as soon as someone opens it. The macro wil do things such as Creation of Pivot Charts, Auto selecting filters of the pivots and so forth. Nothing too fancy.</p>
  
  <p><strong>Problem:</strong></p>
  
  <p>When i manually open the Excel file, the macro does not work, raising this error:</p>
  
  <p><img src="https://i.stack.imgur.com/Fwl0N.png" alt="Funky Excel Error"></p>
  
  <p>On this line of code</p>
  
  <p><img src="https://i.stack.imgur.com/WG86H.png" alt="Not a fancy line of code"></p>
  
  <p>But, when i wait for the document to stop loading, then manually executes the macro, it works just as expected. </p>
  
  <p>I think that the cause might be related to the data not being "ready" to be read once the <code>Workbook_Open</code> event Triggers.</p>