I need some help handling an error. The below code takes a excel file and imports it into the Access database. It works fine as long as the file already exists but if something happens and that file doesn't exist, I get an error saying it can't find the object to (cant find object to delete)
Option Compare Database
Public Function ImportSheet()
Dim excelapp As Object
Set excelapp = CreateObject("excel.application")
Dim wb As Object
Set wb = excelapp.Workbooks.Open("FILEPATH\BOAT_001.xlsx")
Dim numberofrows As Integer
numberofrows = 1 + excelapp.Application.CountA(wb.worksheets("Sheet1").Range("A2:A10000"))
DoCmd.DeleteObject acTable, "
DoCmd.TransferSpreadsheet acLink, acSpreadsheetTypeExcel9, "
wb.Close
'same code as above but for boat_002, etc
Option Compare Database
Public Function ImportSheet()
Dim excelapp As Object
Set excelapp = CreateObject("excel.application")
Dim wb As Object
Set wb = excelapp.Workbooks.Open("FILEPATH\BOAT_001.xlsx")
Dim numberofrows As Integer
numberofrows = 1 + excelapp.Application.CountA(wb.worksheets("Sheet1").Range("A2:A10000"))
DoCmd.DeleteObject acTable, "
BOAT_001
"DoCmd.TransferSpreadsheet acLink, acSpreadsheetTypeExcel9, "
BOAT_001
", "FILEPATH
\BOAT_001
.xlsx", True, "Sheet1!A2:J" & numberofrowswb.Close
'same code as above but for boat_002, etc