【发布时间】:2015-07-25 05:02:05
【问题描述】:
我有一个宏/vba 可以在编辑后保存几个 Excel 工作簿。但是,有时其他用户可能会在读/写模式下使用其中一个 excel 文件。
出现下面的消息框,我所做的是一直单击“否”,直到用户使用完 Excel 文件
一旦出现消息框下方的文件是空闲的,我点击“读写”,我的代码从它停止的地方恢复(图片示例)
问题 - 如何让 Access VBA 或 Excel VBA 为我点击“否”?
注意:我使用了Application.DisplayAlerts 和DoCmd.SetWarnings,默认都是Yes。 (或者可能是我没有正确实现它们)。
代码:
Function RefreshExcelTables()
On Error GoTo Error
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
Error:
If Err.Number = 1004 Then
call pause(5)
Resume
End If
Set ExcelApp = Nothing
End Function
Public Function Pause(intSeconds As Integer)
Dim dblStart As Double
If intSeconds > 0 Then
dblStart = Timer()
Do While Timer < dblStart + intSeconds
Loop
End If
End Function
【问题讨论】:
-
什么代码导致显示上述消息?你确实改进了你的问题。
-
Maciej Los - 我已经包含了我的代码