title: Get Workbook reference from Open File dialog
body: <p>I'm using an Excel 2013 macro to extract data from a user-selected workbook and my vba is a bit rusty.</p>
  
  <p><code>Application.GetOpenFilename</code> prompts the user for a file location, opens the file and returns a string.  <code>Workbooks.Open(string)</code> returns a Workbook - if you know the name in advance.</p>
  
  <p>I want to combine these to ask the user which file to open, and return a Workbook.</p>
  
  <p>Based on Frank's answer here (<a href="https://stackoverflow.com/questions/25153342/open-a-workbook-using-filedialog-and-manipulate-it-in-excel-vba">Open a workbook using FileDialog and manipulate it in Excel VBA</a>) I've tried this:</p>
  
  <pre><code>Function openDataFile() As Workbook
  '
    Dim wb As Workbook
    Dim filename As String
    Dim fd As Office.FileDialog
    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    fd.AllowMultiSelect = False
    fd.Title = "Select the file to extract data"
    'filename = fd.SelectedItems(1)
    Set wb = Workbooks.Open(fd.SelectedItems(1))
    openDataFile = wb
  
  End Function
  </code></pre>
  
  <p>but this falls over on the commented line with <code>Run-time error '5': Invalid procedure call or argument.</code></p>
  
  <p>How do I prompt the user to open an excel file, and return a reference to it as a workbook?</p>