importing excel worksheet to Access table

J

Jill Lin

I still can't figure out what I am doing wrong in my code. I am writing a
code in Excel VBA where, when user press the button, the program will
automatically import the specified Excel spreadsheet to an Access table. I
use the DoCmd.TransferSpreadsheet function but I keep getting "Variable not
defined" error. Please help.

Here is my code.
Sub OpenAccess()
Dim oApp As Object
Dim LPath As String

LPath = "C:\folder\test.mdb"
Set oApp = CreateObject("Access.Application")
oApp.OpenCurrentDatabase LPath
oApp.DoCmd.TransferSpreadsheet acImport, _ acSpreadsheetTypeExcel9,
"table1", "C:\clients\CTim\Additional_Accounts.xls", True 'table1 is a
table in the test.mdb where I want the Excel file to be copied to.

Thanks,
Jill

url:http://www.ureader.com/gp/1052-1.aspx
 
K

Ken Snell [MVP]

EXCEL does not know the values of the ACCESS intrinsic concstants such as
acSpreadsheetTypeExcel9, Replace acSpreadsheetTypeExcel9 with the number 8:
oApp.DoCmd.TransferSpreadsheet acImport, _
acSpreadsheetTypeExcel9, "table1",
"C:\clients\CTim\Additional_Accounts.xls", True
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top