title: Getting a runtime error 438 and not sure why
body: <p>I am using MSO Access 2013, and writing some code to open the file dialog for the user to select an Excel file to import information in to a table in the database. I get the Runtime error, and not exactly sure why. Would anyone kindly help with this situation? The code is as follows</p>
  
  <pre><code>    Dim xlApp As Excel.Application
      Dim xlWrksht As Excel.Worksheet
      Dim xl As Excel.Application
      Dim xlsht As Excel.Worksheet
      Dim xlWrkBk As Excel.Workbook
  
      If MsgBox("This will create a new job by importing a Start Up worksheet. 
      Do you want to continue?", vbYesNo + vbQuestion, "Well Startup - Import 
      File") = vbYes Then
      'prompt user for file
      Const msoFileDialogFilePicker As Long = 3
      Dim objDialog As Object
      Dim fPath As String
      Set objDialog = Application.FileDialog(msoFileDialogFilePicker)
      With objDialog
          .AllowMultiSelect = False
          .Show
          If .SelectedItems.Count = 0 Then
              MsgBox "No file selected."
              Exit Sub
          Else
              fPath = .InitialFileName
          End If
      End With
      'open db and store data in tables
      Set myRec = CurrentDb.openrecordset("WellProject")
      Set xlApp = CreateObject("Excel.Application")
      Set xlWrksht = xlApp.Open(fPath).Worksheets("1") '&lt;----where I get the error
      Set xl = CreateObject("Excel.Application")
      Set xlWrkBk = GetObject(fPath)
      Set xlsht = xlWrkBk.Worksheets(1)
      '1st table
      myRec.AddNew
      myRec.Fields("Job") = xlWrksht.Cells(2, "F")
      myRec.Fields("spud_date") = xlWrksht.Cells(10, "B")
      myRec.Update
      Else: Exit Sub
      End If
  </code></pre>
  
  <p>The directory path is stored in the variable fPath. This works fine. I believe the issue would be somewhere with the Excel file, but not sure. Any ideas? Thanks everyone!</p>