Excel ScreenUpdating错误和仍然闪烁的屏幕 [英] Excel ScreenUpdating False and still flickering screen

查看:418
本文介绍了Excel ScreenUpdating错误和仍然闪烁的屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下简单的代码来关闭一系列打开的工作簿.我刚刚切换到Excel 2013,在此新版本中,对于未隐藏的每个工作簿,我的屏幕在Excel中始终闪烁一个白色窗口.

I have the following simple code to close a range of open workbooks. I have just switched to Excel 2013 and in this new version my screen keeps flashing a white window in Excel for each workbook that is unhidden.

如何关闭烦人的屏幕闪烁?

How can I get that annoying screen flicker to shut off?

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

推荐答案

已经阅读了大多数与潜在解决方案有关的答案,很遗憾地告诉您,当您尝试停止闪烁时,它们都不对我有用.使工作表可见/不可见.

Having read most of the answers with potential solutions, I'm sorry to tell you none of them worked for me when trying to stop the flickering at the moment of making a worksheet visible/invisible.

然后,我想到闪烁可能是由工作簿的自动重新计算引起的,所以我尝试了一下,并且成功了!

Then, it came up to me that the flickering could be caused by the automatic recalculation of the workbook, so I gave it a try, AND IT WORKED!

这就是我正在使用的:

 Private Sub StopFlickering (ws As Worksheet)

  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

End Sub

在工作簿中任何地方使用它的示例:

Example to use it from anywhere in the workbook:

StopFlickering ThisWorkbook.Worksheets("Worksheet Name")

我希望它不仅对我有用,而且对尝试的人也有用.祝你好运,让我知道.

I hope it works not just for me, but for anyone who gives it a try. Good luck, and let me know.

这篇关于Excel ScreenUpdating错误和仍然闪烁的屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆