Using VBA Access, I'm trying to edit the below code. So that it first checks if an excel file is open , if already open wait till file is closed then resume code? this needs to be done for each file 1,2,3.
- Check if excel file is open
- If open wait(Pause) till closed then resume code (Refresh table ,save, close)
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