使用VBA Access,我尝试编辑以下代码。这样它首先检查excel文件是否打开,如果已打开等待文件关闭然后恢复代码?这需要为每个文件1,2,3。
完成重复下一个文件的处理。
Function RefreshExcelTables()
Dim ExcelApp As Object
Set ExcelApp = CreateObject("Excel.Application")
ExcelApp.workbooks.Open "c:\test\Test_Sheet1.xlsb"
ExcelApp.ActiveWorkbook.refreshall
ExcelApp.ActiveWorkbook.Save
ExcelApp.ActiveWindow.Close
ExcelApp.workbooks.Open "c:\test\Test_Sheet2.xlsb"
ExcelApp.ActiveWorkbook.refreshall
ExcelApp.ActiveWorkbook.Save
ExcelApp.ActiveWindow.Close
ExcelApp.workbooks.Open "c:\test\Test_Sheet3.xlsb"
ExcelApp.ActiveWorkbook.refreshall
ExcelApp.ActiveWorkbook.Save
ExcelApp.ActiveWindow.Close
Set ExcelApp = Nothing
End Function
答案 0 :(得分:0)
在Outlook中测试
Sub Test()
Dim ExcelApp As Object
Dim X, X1
X = Array("c:\test\Test_Sheet1.xlsb", "c:\test\Test_Sheet2.xlsb")
For Each X1 In X
On Error Resume Next
Set ExcelApp = GetObject(X1).Application
On Error GoTo 0
If Not ExcelApp Is Nothing Then
With ExcelApp.Workbooks(Right$(X1, Len(X1) - InStrRev(X1, "\")))
.RefreshAll
.Save
.Close
End With
Set ExcelApp = Nothing
End If
Next X1
End Sub