Excel ScreenUpdating虚假和仍然闪烁的屏幕

我有以下简单的代码来closures一系列打开的工作簿。 我刚刚切换到Excel 2013,在这个新版本中,我的屏幕在Excel中为每个未隐藏的工作簿不断闪烁白色窗口。

我怎样才能让烦人的屏幕闪烁closures?

Sub CloseFiles() On Error Resume Next Application.ScreenUpdating = False Application.StatusBar = "Please wait while files are closed." Application.DisplayAlerts = False Dim rCell As Range For Each rCell In Range("Files") Application.StatusBar = "Closing file " & rCell.Value If rCell.Value <> "" Then Windows(rCell.Value).Visible = True Workbooks(rCell.Value).Close SaveChanges:=True End If Next rCell Application.WindowState = xlMaximized Windows("Filename.xlsm").Activate Application.DisplayAlerts = True Application.StatusBar = False Application.ScreenUpdating = True End Sub 

我已经确定了解决这个问题的最简单的方法是从一个单独的子程序中调用代码。

 Sub startcode() Application.ScreenUpdating = False Call myrunningsub() Application.ScreenUpdating = True End Sub Sub myrunningsub() 'your code here End Sub 

这似乎在绑定Application.ScreenUpdating参数。 注意我在Windows 7 64位中使用Excel 2013。

阅读了大多数解决scheme的答案后,我很抱歉地告诉你们,在试图阻止工作表可见/不可见时闪烁的时候,他们都没有为我工作。

然后,我觉得闪烁可能是由于工作簿的自动重新计算造成的,所以我尝试了一下,而且工作得很好!

这就是我正在使用的:

Private Sub StopFlickering(ws作为工作表)

  Application.Calculation = xlManual Application.ScreenUpdating = False 'Make the worksheet visible/invisible according to previous condition 'Instead, use "= True" or "= False", if it is the specific case ThisWorkbook.Worksheets(ws.Name).Visible = _ Not ThisWorkbook.Worksheets(ws.Name).Visible '(any other code in here) 'Don't forget to restore previous settings Application.ScreenUpdating = True Application.Calculation = xlAutomatic 

结束小组

从工作簿的任何位置使用示例:

StopFlickering ThisWorkbook.Worksheets(“工作表名称”)

我希望它不仅适用于我,而且适用于任何尝试的人。 祝你好运,让我知道。

(PS:我希望这个回答的格式能够遵守规则,这是我第一次在任何地方做这样的事情,对于任何错误,我提前道歉。

正如Siddharth所说(我只是在后面一秒)……为什么要让书籍可见 – 只需closures每一个并保存更改即可。

其他几点:
1.我曾经玩过StatusBar的应用程序,但是不再烦恼 – 应用程序崩溃的次数太多了,并且在这个应用程序栏上留下了一个不需要的消息!
2. On Error Resume Next程序的stream程中需要下一个例如,你是否使用它故意打错误,然后移动到下一行代码? 如果没有,那么只是隐藏一个错误可能是危险的….有时最好让程序错误,然后你知道你的立场,然后可以解决这个问题。

 Sub CloseFiles() On Error Resume Next Application.ScreenUpdating = False Application.StatusBar = "Please wait while files are closed." Application.DisplayAlerts = False Dim rCell As Range For Each rCell In Range("Files") Application.StatusBar = "Closing file " & rCell.Value If rCell.Value <> "" Then 'Windows(rCell.Value).Visible = True '::::::::why bother with this? Workbooks(rCell.Value).Close SaveChanges:=True End If Next rCell Application.WindowState = xlMaximized Windows("Filename.xlsm").Activate Application.DisplayAlerts = True Application.StatusBar = False Application.ScreenUpdating = True End Sub 

我有相同的“问题”,我使用这种types的代码(我添加一个doevents和一个.displaystatusbar = true)

 Sub CloseFiles() err.clear On Error Resume Next with Application .ScreenUpdating = False .displaystatusbar = true 'kinda need this line .StatusBar = "Please wait while files are closed." doevents 'magic trick .DisplayAlerts = False .calculation= xlManual 'sometimes excel calculates values before saving files .enableevents=false 'to avoid opened workbooks section open/save... to trigger end with 'code with application .StatusBar = False .displaystatusbar = false .DisplayAlerts = True .ScreenUpdating = True .enableevents=true .calculation= xlAutomatic end with End Sub 

保护/取消保护表单将激活表单,尽pipeApplication.ScreenUpdating的设置。 这是我闪烁的原因。