我做过研究,发现这个话题很少。我制作了一个excel宏来在线保存文件,但是希望将代码移植到Access中以将所有代码放在一个地方(我通过Access调用Excel宏)。 这是Excel宏。
ThisWorkbook.RefreshAll
Application.CalculateUntilAsyncQueriesDone
ActiveWorkbook.ServerViewableItems.DeleteAll
ActiveWorkbook.ServerViewableItems.Add ActiveWorkbook.Sheets("Data")
ActiveWorkbook.SaveAs Filename:= _
"website" _
, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
它适用于Excel。当我将其移动到Access时,我稍微更改了代码。
Dim objWorkbook As Object
Dim sourcefilepath As String
Set objXL = CreateObject("Excel.Application")
objXL.Application.Visible = False
objXL.displayalerts = False
'objXL.Application.Run ("SharepointUpload")'
objXL.ActiveWorkbook.RefreshAll
objXL.Application.CalculateUntilAsyncQueriesDone
objXL.ActiveWorkbook.ServerViewableItems.DeleteAll
objXL.ActiveWorkbook.SaveAs FileName:= _
"website" _
, FileFormat:=xlExcel12, CreateBackup:=False
objWorkbook.Close
objXL.Quit
Set objWorkbook = Nothing
Set objXL = Nothing
然而,我一直收到运行时错误' 1004' SaveAs作为Workbook类的方法失败。我认为这是一种在Access中为Excel设置变量的方法。任何帮助表示赞赏