I am attempting to export a worksheet from Excel 2007 to Access 2007 on Windows 7 including creating a new table. I have tried the following VBA in Excel but it states "Compile Error User-defined types not defined" and then highlights the first variable declaration for the Access object. I have the Microsoft ActiveX Data Objects 6.1 Library referenced.
What is wrong?
Dim acc As New Access.Application
Dim ws As Worksheet
Dim ThisWorkbook As Workbook
Dim a As Long
Dim b As Long
Set ThisWorkbook = ActiveWorkbook
Set ws = ThisWorkbook.Sheets("CompleteNoFormat3")
a = ws.UsedRange.Rows.Count
b = ws.UsedRange.Columns.Count
acc.OpenCurrentDatabase "CustDB.mdb"
acc.DoCmd.TransferSpreadsheet _
TransferType:=acImport, _
SpreadSheetType:=acSpreadsheetTypeExcel12Xml, _
TableName:="CustExportTable", _
Filename:=Application.ActiveWorkbook.FullName, _
HasFieldNames:=True, _
Range:="BAPCompletNoFormat$A1:" & a & B
acc.CloseCurrentDatabase
acc.Quit
Set acc = Nothing