vba - 在打开和关闭 application.screenupdating 时更新打开的 Excel 工作表上的单元格

标签 vba excel excel-2013

这是一个大宏的小问题,我正在阅读日志文件并通过将它们写入多个工作表来准备数据。我不想看到所有这些写作,所以我关闭了屏幕更新,但是我想看到一些进展,所以我不时切换屏幕更新我激活顶部工作表,在一些中写入一些进度数据单元格并再次关闭屏幕更新。这在 Excel 2010 中运行良好,但上周我升级到 Excel 2013 并且在宏完成之前没有更多可见的更新。我添加了 0.3 秒的暂停,但现在只更新时间,而不是处理的站点数量。有任何想法吗?

Application.ScreenUpdating = True  'To write the elapsed time and the number of found sites on the performance monitor sheet
PerfMon.Activate
PerfMon.Range("B4") = Now - StartPoint
PerfMon.Range("D4") = SiteCnt
Application.Wait (Now + (0.3 / 86400))
Application.ScreenUpdating = False

谢谢,汉斯

最佳答案

最好的解决方案似乎是启用状态栏。在不确切知道您的宏是什么的情况下,我建议您将工作簿中的变量之一设置为整数,并在状态栏中跟踪当前进度。也许这是“Now - StartPoint”或“SiteCnt”,否则您可以使用新文本定期更新状态栏。

如果您使用整数选项,这是一个示例:

[...]
 Application.ScreenUpdating = False
 Application.DisplayStatusBar = True
 Dim i As Integer
 For i = 2 To Sheets.Count       ' example from my macro but you could use any repeating process
       Worksheets(i).Activate
       Application.StatusBar = "Updating Filings for " & ( i - 1 ) & " of " & (Sheets.Count - 1) & "   |   " & Format (( i - 1 )) / (Sheets.Count - 1), "0%") & "Complete"
 Next i
 Application.StatusBar = ""
 Application.DisplayStatusBar = False
[...]   

如果您使用 text 选项,这是一个示例:
[...]
 Application.ScreenUpdating = False
 Application.DisplayStatusBar = True
 Application.StatusBar = "Reading log files"
 [...]
 Application.StatusBar = "Preparing data"
 [...]
 Application.StatusBar = "Formatting data"
 [...]
 Application.StatusBar = ""
 Application.DisplayStatusBar = False
[...]   

关于vba - 在打开和关闭 application.screenupdating 时更新打开的 Excel 工作表上的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33681671/

相关文章:

excel - 从范围(对象)中删除单元格

excel - 如何用 VBA 中的直接单元格引用替换所有偏移公式?

arrays - VBA:创建类模块数组

excel - 我想检查一列值是否存在于excel的另一列中?

python - 在 xlsxwriter 的 add_series 中传递变量

excel - 将细胞彼此连接起来;让单元格更新链接的单元格,反之亦然

c# - 使用 SOAP Web 引用将 C# 类编译为 .dll 错误 CS0234

excel - 如果有超链接,则可以更改形状颜色

VBA 验证。添加方法失败

Excel VBA - 扫描范围并删除空行