title: Excel VBA can't open Workbook
body: <p>First: I'm using Excel 2007, but the code has to work for Excel 2003 as well.</p>
  
  <p>My problem is the following: I need to access cells in a different workbook, which may be closed. The following code can be found all around the web:</p>
  
  <pre><code>Function Foo()
      Dim cell As Range
      Dim wbk As Workbook
      Set wbk = Workbooks.Open("correct absolute path")
      ' wbk is Nothing here so the next statement fails.
      Set cell = wbk.Worksheets("Sheet1").Range("A1")
      Foo = cell.Value
      wbk.Close
  End Function
  </code></pre>
  
  <p>sadly, wbk is Nothing after the open statement (I'd love to give a better error message, but no idea how I'd do that; what I'd give for a real IDE and an useful language :/). The absolute path is correct and points to a valid excel xlsx file.</p>
  
  <p>Also I assume the best way to do this, is to "cache" the workbook and not open/close it every time the function is called? Any possible problems with that (apart from having to handle the situation when the workbook is already open obviously)?</p>
  
  <p>Image while stepping through:
  <img src="https://i.stack.imgur.com/cnI7R.png" alt="debugging info"></p>