[英]exporting access tables to excel
I am trying to use the following code to export tables from access to excel 我正在尝试使用以下代码从对Excel的访问中导出表
I am getting error object does not support property or method at the end 我收到错误对象,最后不支持属性或方法
Set objexcel = New Excel.Application
objexcel.Visible = True
If Dir("C:\reports\Data_Analysis1.xls") = "" Then
objexcel.Workbooks.Add
Set wbexcel = objexcel.ActiveWorkbook
Set objSht = wbexcel.Worksheets("Sheet1")
Else
Set wbexcel = objexcel.Workbooks.Open("C:\Documents and Settings\TAYYAPP\Desktop\test folder\reports\ERROR REPORT4.xls")
Set objSht = wbexcel.Worksheets("Sheet1")
End If
objSht.Activate
objexcel.DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "UTYP_Anzahl", "C:\Reports\Data_Analysis1.xls", True
DoCmd as in "DoCmd.TransferSpreadsheet" is an MS Access command, not an excel command. “ DoCmd.TransferSpreadsheet”中的DoCmd是MS Access命令,而不是excel命令。 I think that is your problem.
我认为那是你的问题。
If this VBA is running inside MS Access then just refer to it as 如果此VBA在MS Access中运行,则只需将其称为
DoCmd.TransferSpreadsheet
Not 不
objexcel.DoCmd.TransferSpreadsheet
Also, if that is what you're doing, you don't need to manually create an excel file with Execl Automation, Access will do that for you. 另外,如果您正在执行此操作,则无需使用Execl Automation手动创建excel文件,Access会为您完成。
Apologies if I have misunderstood what you're doing, but I think all you need is the TransferSpreadSheet command. 抱歉,如果我误解了您的操作,但我认为您所需要的只是TransferSpreadSheet命令。
该答案适用于Excel对象,可能会有所帮助,因为它允许您自动设置excel文件的格式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.