使用 VBA 如何防止打开文件时出现消息?
Using VBA how to prevent a message from appearing when opening a file?
我正在创建一个宏,它可以打开大量文件,刷新它们,然后保存并关闭。一切都是 运行 顺利,但是对于 2 个文件,当它们打开时会弹出一条消息,上面写着 "Files run on an inclusion list - titles may be missing." 这会停止宏,直到按下 "ok"。我以前用过 "Application.DisplayAlerts = False" 但它似乎在这里不起作用。我的代码如下:
Public Sub Refresh_All()
Dim filepathstr As String
Dim filename As String
Dim wbk As Workbook
filepathstr = Sheet1.Range("filepath").Value
For Each cell In Sheet1.Range("workbooks")
If Not cell.Value = "" Then
filename = cell.Value
Application.DisplayAlerts = False
Set wbk = Workbooks.Open(filepathstr & filename, False)
''''**REFRESH**''''''
SAPBexrefresh (True)
Application.DisplayAlerts = False
wbk.Save
wbk.Close False
Application.DisplayAlerts = True
End If
Next cell
MsgBox "The Macro has finished; BW Reports are refreshed."
End Sub
如有任何帮助,我们将不胜感激!
添加
Application.EnableEvents=False
打开wb之前然后设置回true
或者,使用:
Application.AutomationSecurity=msoAutomationSecurityForceDisable
记得设置回用户拥有的任何内容...
我正在创建一个宏,它可以打开大量文件,刷新它们,然后保存并关闭。一切都是 运行 顺利,但是对于 2 个文件,当它们打开时会弹出一条消息,上面写着 "Files run on an inclusion list - titles may be missing." 这会停止宏,直到按下 "ok"。我以前用过 "Application.DisplayAlerts = False" 但它似乎在这里不起作用。我的代码如下:
Public Sub Refresh_All()
Dim filepathstr As String
Dim filename As String
Dim wbk As Workbook
filepathstr = Sheet1.Range("filepath").Value
For Each cell In Sheet1.Range("workbooks")
If Not cell.Value = "" Then
filename = cell.Value
Application.DisplayAlerts = False
Set wbk = Workbooks.Open(filepathstr & filename, False)
''''**REFRESH**''''''
SAPBexrefresh (True)
Application.DisplayAlerts = False
wbk.Save
wbk.Close False
Application.DisplayAlerts = True
End If
Next cell
MsgBox "The Macro has finished; BW Reports are refreshed."
End Sub
如有任何帮助,我们将不胜感激!
添加
Application.EnableEvents=False
打开wb之前然后设置回true
或者,使用:
Application.AutomationSecurity=msoAutomationSecurityForceDisable
记得设置回用户拥有的任何内容...