从访问excel 2007导出数据

时间:2015-07-02 08:28:40

标签: excel vba excel-vba ms-access access-vba

我是vba编码的新手,我正面临着这个问题。

我需要将表从Access DB传输到Excel

但每当我尝试运行代码时 它会出现错误,表明该表不存在于数据库

我的代码:

 Sub hello()
 Call TransfertoExcel
 End Sub
 Public Function TransfertoExcel()
 On Error GoTo errorHandler

 Dim strTable As String
 Dim worksheetpath As String

 worksheetpath = "C:\Users\Desktop\test.xlsx"
 strTable = "TestTable"

 DoCmd.TransferSpreadsheet transfertype:=acExport, _
 spreadsheettype:=acSpreadsheetTypeExcel12, _
 TableName:=strTable, FileName:=worksheetpath, _
 hasfieldnames:=True

 errorHandlerexit:
 Exit Function

 errorHandler:

 MsgBox "Error no:" & Err.Number _
 & "; Description: " & Err.Description
 Resume errorHandlerexit

 End Function

0 个答案:

没有答案