title: VBA Add-In can't reference Worksheet on Auto-Open
body: <p>I have an excel add-in and I want it to run certain macros whenever a template is opened. This runs fine if I open excel and then run the auto_open sub manually but throws 'Run-Time Error 9. Subscript out of range' when opening excel.</p>
  
  <p>It seems like the add in is loading and trying to run before the template has loaded so that when trying to reference a specific sheet in the workbook it fails to find anything.</p>
  
  <p>Specifically the error comes at </p>
  
  <pre><code>Set shtData = Workbooks("Example_Template.xlsm").Worksheets("Test")
  </code></pre>
  
  <p>How can I force the auto_open macro to run once the worksheets are loaded?</p>
  
  <p>My auto open code is:</p>
  
  <pre><code>Sub Auto_Open()
     Set clsAppEvents = New clsApplicationEvents
  
     Application.Run "PerformanceOpen"
  
  End Sub
  </code></pre>
  
  <p>And the macro I am trying to run contains:</p>
  
  <pre><code>Private Sub PerformanceOpen()
  
  Dim shtData As Worksheet
  
  Set shtData = Workbooks("Example_Template.xlsm").Worksheets("Test")
  shtData.Activate
  </code></pre>