title: Do While Loop Code for Excel Declaration
body: <p>I have very big excel file takes long time to open. </p>
  
  <p>I want to declare xlApp without error as soon as file is ready. </p>
  
  <p>Following code need to be repaired.</p>
  
  <pre><code>Process.Start("C:\Book1.xlsx")
  Do While SOMETHING
     Application.DoEvents()
  Loop
  Dim xlApp As Excel.Application = Nothing
  xlApp = CType(GetObject(Nothing, "Excel.Application"), Excel.Application)
  </code></pre>
  
  <p>If I run following line without opening Book1 then following line gives error. </p>
  
  <pre><code>xlApp = CType(GetObject(Nothing, "Excel.Application"), Excel.Application)
  </code></pre>
  
  <p>Using following code is not good idea because opening time of Book1.xlsx always different.</p>
  
  <pre><code> Threading.Thread.Sleep(10000)
  </code></pre>