Access / Excel VBA – 删除显示警报和消息

我有一个访问macros/ VBA编辑后保存几个Excel工作簿。 但有时其他用户可能正在使用其中一个excel文件在读/写模式。

出现下面的消息框,我所做的是继续单击否直到用户完成使用Excel文件

在这里输入图像说明

一旦文件出现在消息框下方,我点击“读写”,我的代码从停止的位置恢复(图像示例)

在这里输入图像说明

问题 – 如何获得Access VBA或Excel VBA为我点击“否”?

注意:我使用了Application.DisplayAlertsDoCmd.SetWarnings ,默认值是Yes 。 (或者可能是我没有正确实施)。

码:

Access / Excel VBA – 时间延迟

 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 

您可以从以下选项调整开始。

 DoCmd.SetWarnings False 

更多信息: DoCmd.SetWarnings方法(Access)和DoCmd.SetWarnings方法(Access开发人员参考) 。

对于Excel.Application对象,您可能必须使用该实例的等效项。

 ExcelApp.DisplayAlerts = false 

Excel的DisplayAlerts的参考文档位于Application.DisplayAlerts属性中 。

你可以试试Docmd.setwarnings False