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