[英]vba access - Check if excel file is open
Using VBA Access, I'm trying to edit the below code. 使用VBA Access,我正在尝试编辑以下代码。 So that it first checks if an excel file is open , if already open wait till file is closed then resume code?
因此,它首先检查excel文件是否已打开,如果已经打开,请等到文件关闭后再恢复代码? this needs to be done for each file 1,2,3.
这需要针对每个文件1,2,3进行。
Repeat process for the next file. 对下一个文件重复此过程。
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
tested in Outlook 在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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.