My apologies in advance for inquiring about something that I see many similar post on. I am trying to import data from an Excel workbook into a single Access table using a mix of code from several threads. My Excel workbook has many sheets, but thankfully, I need the same range from each sheet (c2:Q17281), and all to be put in one Access table. This is my first project using VBA with Access (I've done a little with Excel VBA before).
I am getting an "Object required" error, regardless of whether or not I use "set", and whether or not I use the file extension (.xls). My code is below. I'd greatly appreciate any help.
Public Sub ProcessExcelFile1()
Dim objXL As Excel.Application
Dim objWkb As Excel.Workbook
Dim objSht As Excel.Worksheet
Dim mypath
mypath = "G:\DataFolder\"
Set objWkb = mypath & "DataFile1"
With objWkb
For Each objSht In .Worksheets
DoCmd.TransferSpreadsheet acImport, , "MyNewTable", mypath & objWkb, False, "c2:q17281"
Next
End With
End Sub
I am getting an "Object required" error, regardless of whether or not I use "set", and whether or not I use the file extension (.xls). My code is below. I'd greatly appreciate any help.
Public Sub ProcessExcelFile1()
Dim objXL As Excel.Application
Dim objWkb As Excel.Workbook
Dim objSht As Excel.Worksheet
Dim mypath
mypath = "G:\DataFolder\"
Set objWkb = mypath & "DataFile1"
With objWkb
For Each objSht In .Worksheets
DoCmd.TransferSpreadsheet acImport, , "MyNewTable", mypath & objWkb, False, "c2:q17281"
Next
End With
End Sub