VBA 将 Excel 文件从 Access 保存为 .xls

VBA save Excel file as .xls from Access

您好,我必须执行从 Excel 文件导入到 Access 数据库,不要重复。唯一可以做到这一点的方法是创建 table,您可以在其中导入 Excel 数据,然后通过构建查询将其附加到目标 table。问题是这个 Excel 文件必须是 .xls 格式,none 其他格式对我有用(不知道为什么)。我怎样才能从 Access 做到这一点 - 无需打开 Excel 工作簿,只需更改它的扩展文件名即可?这是我尝试过的(我收到错误:“对象不支持此 属性 或方法”)

Dim XFile As Excel.Application


Set XFile = CreateObject("Excel.Application")
XFile.Workbooks.Open "C:\Users\Mike\Desktop\Copy.xlsx", True

XcelFile.SaveAs Filename:="C:\Users\Mike\Desktop\Copy.xlsx", FileFormat:=56
XFile.Workbooks.Close

End Sub

如您所见,我需要从 .xlsx 格式保存,这是 Excel 2013 的默认格式。

非常感谢任何帮助!!

感谢@Porcupine911,即使没有打开工作簿也能成功:)

Dim XcelFile As Excel.Application
Dim wb As Excel.Workbook

Set XcelFile = New Excel.Application

Set wb = XcelFile.Workbooks.Open("Filepath here")

wb.SaveAs Filename:="Filename here, with different destination and desirable extension", FileFormat:=56
wb.Close
Set XcelFile = Nothing

End Sub