【问题标题】:Access/Excel VBA - Remove display alerts and messagesAccess/Excel VBA - 删除显示警报和消息
【发布时间】:2015-07-25 05:02:05
【问题描述】:

我有一个宏/vba 可以在编辑后保存几个 Excel 工作簿。但是,有时其他用户可能会在读/写模式下使用其中一个 excel 文件。

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

一旦出现消息框下方的文件是空闲的,我点击“读写”,我的代码从它停止的地方恢复(图片示例)

问题 - 如何让 Access VBA 或 Excel VBA 为我点击“否”?

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

代码:

Access/Excel VBA - Time delay

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 - 我已经包含了我的代码

标签: excel ms-access vba


【解决方案1】:

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

DoCmd.SetWarnings False

更多信息请访问:DoCmd.SetWarnings Method (Access)DoCmd.SetWarnings Method (Access Developer Reference)

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

ExcelApp.DisplayAlerts = false

Excel DisplayAlerts 的参考文档位于Application.DisplayAlerts Property

【讨论】:

  • 另外应该测试文件是否被其他人打开,我想这是OP的主要关注点。
  • @user3819867 - 好点。这将需要比一行更多的代码。了解 Excel 2013 及其处理应用程序实例和应用程序窗口的特殊方式是否会在这方面有所帮助。
  • 我只是在监视,因为这将是一个地狱While ... Wend 循环。
【解决方案2】:

你可以试试 Docmd.setwarnings False

【讨论】:

    猜你喜欢
    • 2015-05-20
    • 1970-01-01
    • 1970-01-01
    • 2014-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-04
    相关资源
    最近更新 更多