My skill level is moderate.
My access DB opens and imports an Excel spreadsheet successfully. When I test it again it says Excel is in use.
I checked the Task Manager, no Excel. I shut down my Access DB and restarted. No success.
Finally I shut everything down and rebooted. No success. Still says Excel is open.
I have read most of the posts and tried several code suggestions. None work.
I have attached a screen snap of error messages. My variable TxtFilePath works fine.
This import code has worked 2 times.
Private Sub CmdImport_Click()
Dim Dlg As FileDialog
Dim txtFilePath As String
Set Dlg = Application.FileDialog(msoFileDialogFilePicker)
With Dlg
.title = "Select the file you want to import"
.AllowMultiSelect = False
If .Show = -1 Then
txtFilePath = .InitialFileName
Else
Exit Sub
End If
End With
DoCmd.TransferSpreadsheet acImport, 10, "Tbl_ImportVendorsTemp", txtFilePath, True, "A1:I407"
End Sub
I have tried many different chunks of close Excel code. I understand Excel may be running invisible. I read about that but it was above my level to understand or implement. After rebooting I am not sure that is actually my problem.
I need to test and see if Excel is open. Then I need to close or Kill Excel. Then import the new spreadsheet. It is fine if Excel opens and displays the spreadsheet.
No variation of the code below works.
Dim objXL As Object
Dim xlWB As Object
Set objXL = CreateObject("Excel.Application")
Set xlWB = objXL.Workbooks.Open("C:\Temp\Book1.xlsx")
xlWB.Close False
objXL.Quit
Thanks, Phred