I've found similar questions asked before, but I can't seem to figure it out using those examples.
I'm writing a macro in Excel where the last step needs to import all the data in Sheet1!A:Q (headers in row 1) to Table1 in an Access database. I need to make sure each column in Excel corresponds to the correct field in Access.
I am using Excel 2010/2013 and Access 2010/2013. Code I am currently using is:
Sub AccImport()
Dim acc As New Access.Application
acc.OpenCurrentDatabase "C:\Users\Benjamin\Documents\Database1.accdb"
acc.DoCmd.TransferSpreadsheet _
acImport, _
acSpreadsheetTypeExcel12Xml, _
"Sheet1", _
Application.ActiveWorkbook.FullName, _
True, _
"A1:Q1000" 'Need to change to reflect the last row in the sheet
acc.CloseCurrentDatabase
acc.Quit
Set acc = Nothing
End Sub
The code results in error message, highlighting acc As New Access.Application and displaying "Compile error - User-defined type not defined"
Any help would be greatly appreciated. Thanks!
Dim acc As New Access.Application acc.OpenCurrentDatabase "C:\Users\Benjamin\Documents\Database1.accdb" acc.DoCmd.TransferSpreadsheet _ acImport, _ acSpreadsheetTypeExcel12Xml, _ "tblExcelImport", _ Application.ActiveWorkbook.FullName, _ True, _ "CallLog" acc.CloseCurrentDatabase acc.Quit Set acc = Nothing