Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将数据从access导出到excel 2007_Excel_Ms Access_Vba - Fatal编程技术网

将数据从access导出到excel 2007

将数据从access导出到excel 2007,excel,ms-access,vba,Excel,Ms 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 wor

我是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

它对我有用。检查拼写并打开TestTable。确保模块顶部有
选项Explicit
,我们是否需要启用任何选项,并且表名应为access db中的表?如果使用该代码,则该表必须位于当前数据库中。没有需要启用的选项。我需要提供任何引用吗?如果您没有篡改默认引用,并且数据库没有损坏,则该代码将运行。