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
Use WindowState
in combination with DisplayAlerts
. The user won't see the window minimize, but it will also keep Excel from flickering during a SaveAs
, changing window visibility, or changing workbook/worksheet protection.
Dim iWindowState as Integer
With Application
.ScreenUpdating = False
.DisplayAlerts = False
iWindowState = .WindowState
.WindowState = xlMinimized
End With
'Flickery code
With Application
.ScreenUpdating = True
.DisplayAlerts = True
.WindowState = iWindowState
End With
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!
This is what I'm using:
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.
Protecting/unprotecting a sheet activates the sheet, despite the setting for Application.ScreenUpdating. This was the cause for my flicker.
I have determined the easiest way to solve this is to call the code from a separate subroutine.
Sub startcode()
Application.ScreenUpdating = False
Call myrunningsub()
Application.ScreenUpdating = True
End Sub
Sub myrunningsub()
'your code here
End Sub
This seems to work in binding the Application.ScreenUpdating
parameter. Note I use Excel 2013 in Windows 7 64 bit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With