在你明白之前:Application.DisplayAlerts = False还没有解决我的问题.
我编写了一个VBA过程(在Excel 2010中启动),它循环包含不同Excel文件的数组.循环打开文件,刷新数据,保存并关闭数组中每个项目的文件.我写了一个错误catch子例程,所以我记录哪些excel文件无法打开/刷新/保存等,以便用户可以手动检查它们.
有些文件很大,涉及大量数据在网络中传输; 有时我得到一个对话框:Excel正在等待另一个应用程序完成OLE操作.
我可以Application.DisplayAlerts = False用来禁用消息,但这可能会禁用所有警报,所以我无法捕获错误?
此外,我已经测试了使用该行,它不会停止弹出对话框.如果我按下输入它继续,但几分钟后可能会再次弹出.
有没有办法在没有停止其他警报的情况下专门停止消息?
NB.我的进程有一个Excel控件实例,它运行VBA并打开要在单独实例中刷新的工作簿.
谢谢你的帮助
我的代码的摘录在下面,其中包含刷新元素
Sub Refresh_BoardPivots_Standard()
' On Error GoTo Errorhandler
Dim i
Dim errorText As String
Dim x
Dim objXL As Excel.Application
Set objXL = CreateObject("Excel.Application")
GetPivotsToRefresh ' populate array from SQL
For Each i In StandardBoardPiv
DoEvents
'If File_Exists(i) Then
If isFileOpen(i) = True Then
errorText = i
Failed(failedIndex) = errorText
failedIndex = failedIndex + 1
Else
objXL.Visible = True 'False …Run Code Online (Sandbox Code Playgroud) 我编写了一个VBA过程(在Excel 2010中启动),它循环包含不同Excel文件的数组.循环打开文件,刷新数据,保存并关闭数组中每个项目的文件.这个过程最多需要90分钟才能完成,因此我想要一个安全中断程序,它将在当前迭代完成时停止该过程.
我在do-while循环中包含了代码,其中boolean初始化为False.我在Excel中创建了一个Stop按钮,在按下时将布尔变量设置为True,这样就可以满足do while条件并停止该过程.
停止按钮基于相同的excel文件,该文件初始化打开和关闭excel文件的过程.这意味着excel实例会锁定,因此用户无法按下break按钮并暂停该过程.
如何访问停止按钮?或者是否有另一种方式来启动休息?
我的代码 - 新增06/06/2014 15:12
Sub Refresh_Weekly()
failedIndex = 0
'DoEvents
'Refresh_StandardWeekly ' module 2
'Refresh_NonStandardWeekly ' module 4
Refresh_CRIS ' module 3
If StopMsg <> "" Then
MsgBox StopMsg
ElseIf failedIndex = 0 Then
MsgBox "All Weekly Pivots refreshed"
Else
For x = 0 To failedIndex - 1
OutputMsg = OutputMsg + Failed(x) & ", "
Next x
MsgBox "Pivots which failed to refresh:" & OutputMsg
End If
Erase Failed
OutputMsg = "" …Run Code Online (Sandbox Code Playgroud) 我一直在关注有关将VBA转换为VBScript的文章和问题,但我现在卡住了.以下代码仍然适用于VBA(如果我删除Sub例程调用)但它不会作为脚本运行.
该代码打开与SQL Server的连接以检查表以查看该进程是否已在今天运行并将结果加载到Recordset中.如果该字段设置为No然后它打开Excel工作簿并运行宏.它适用于VBA,但是当我运行与脚本相同的代码时,没有任何事情发生(也没有错误).
你能看出问题所在吗?非常感谢.
NB.有两行cmd.CommandText.注释掉的行旨在始终返回No以仅用于测试目的.
' Author Steve Wolstencroft
' Inititates the Automated Excel Refresh Procedure
Option Explicit
Pivot_Refresh
Public Function ConnectToSQLDwarfP()
On Error Resume Next
ConnectToSQLDwarfP = "Driver={SQL Server Native Client 10.0};Server=DwarfP;Database=DwarfPortable;Trusted_Connection=yes;"
End Function
Public Sub Pivot_Refresh()
On Error Resume Next
Dim cnx
Dim Rst
Set cnx = New ADODB.Connection
cnx.ConnectionString = ConnectToSQLDwarfP
cnx.Open
Dim cmd
Set cmd = New ADODB.Command
cmd.ActiveConnection = cnx
cmd.CommandType = adCmdText
cmd.CommandText = "Select Case When max(DwarfPortable.dbo.fn_GetJustDate(pl.StartDateTime)) …Run Code Online (Sandbox Code Playgroud)