gpt4 book ai didi

vba - 由于 ScreenUpdating = FALSE 不起作用,Excel 2013 和 2016 屏幕闪烁的通用解决方案

转载 作者:行者123 更新时间:2023-12-04 22:32:15 28 4
gpt4 key购买 nike

在 Excel 2013 和 2016 中有几十个关于屏幕闪烁的问题,如 Application.ScreenUpdating = False不像以前那样工作。

Screen Flickering VBA Excel
Excel ScreenUpdating False and still flickering screen
ScreenUpdating = False fails in Excel 2013 and 2016

一种部分解决方案涉及禁用工作表计算,但在某些模型中它们可能是必需的。另一个部分解决方案涉及使工作簿不可见,这要么让用户感到困惑(如果所有工作簿都消失了),要么仍然看到屏幕闪烁(如果你让除一个之外的所有工作簿消失)。

理想情况下,我正在寻找一种解决方案,它允许 DoEvents 运行(这样它看起来不像 Excel 被挂起),允许 StatusBar 可见(用于报告进度),并防止所有其他屏幕闪烁。

为什么微软不能解决这个问题:(

这是一些示例代码,它需要两个空白工作簿(Book1 和 Book2)并导致可怕的屏幕闪烁。

Sub Macro1()
' this worked fine in Excel 2010
Application.ScreenUpdating = False

' this clears all flicker, but the whole of excel disappears
' Application.Visible = False
' this changes the flicker between Book1 and blank white screen
' Application.Workbooks("Book2").Windows(1).Visible = False

' some flickery code
For i = 1 To 10
Windows("Book2").Activate
Call Jiggle("Red")
Windows("Book1").Activate
Call Jiggle("Yel")
Next i

' restore normality
Application.ScreenUpdating = True
Application.Visible = True
End Sub


Sub Jiggle(c As Variant)
For i = 1 To 100
ActiveCell.Offset(1, 0).Select
If (c = "Yel") Then Selection.Interior.Color = 255
If (c = "Red") Then Selection.Interior.Color = 65535
Next i
End Sub

最佳答案

在我看来,您的整个代码可以归结为:

Public Sub Macro1()
Application.ScreenUpdating = False
Workbooks("Cartel2").Activate
ActiveCell.Offset(1).Resize(1000).Interior.Color = 65535
Workbooks("Cartel3").Activate
ActiveCell.Offset(1).Resize(1000).Interior.Color = 255
Application.ScreenUpdating = True
End Sub

关于vba - 由于 ScreenUpdating = FALSE 不起作用,Excel 2013 和 2016 屏幕闪烁的通用解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51854520/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com