Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run TransferSpreadsheet cmd from Excel

Status
Not open for further replies.

mac7attack

Technical User
Jan 31, 2004
47
0
0
US
Hello,

I am trying to export a Excel spreadsheet into a Access database using the TransferSpreadsheet command. I am running a macro in Excel 2003 to format the open spreadsheet then export it to Access. I have gotten the Transfer command to work in Access VBA but not in Excel.

The script line I am using in Excel is:
Code:
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "TestNameTest", "db1.mdb", True

Do I have to create a Database object before running the command or is there another way of doing it?

Thanks
Matt
 
DoCmd is a method of the Access.Application object, so you have to instantiate such object.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks for the quick response PH

So the following should work?
Code:
Dim appAccess as New Access.Application
Set appAccess = CreateObject("Access.Application")

appAccess.DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "TestNameTest", "db1.mdb", True

Thanks
Matt
 

I have tested the script in the last post and now getting an error.

"External table is not in the expected format."

I know in Excel the file name (4th parameter) is a spreadsheet but I am running the script from the spreadsheet that needs to be imported. Where should I specify the Spreadsheet to be imported and the Acces to be imported into?

Matt
 
Just so that anyone reading this post can know the answer here it is.
Code:
Sub ExportTest()

Dim appAccess As New Access.Application
Set appAccess = CreateObject("Access.Application")
Dim strDB As String
Dim TN As String

TN = Date$ & " " & Time$
MsgBox TN
ActiveWorkbook.Save
strDB = "C:\db1.mdb"
appAccess.OpenCurrentDatabase strDB, True
appAccess.DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, TN, ActiveWorkbook.FullName, True
appAccess.CloseCurrentDatabase

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top