1
votes

In my python code I'm setting ScreenUpdating to False before writing data to the sheet and afterwards setting it back to True. Once ScreenUpdating is set to True, the sheet flickers.

code snippet:

self.xlsApp.ScreenUpdating = False                                        
#Write some data here to excel sheet      
self.xlsApp.ScreenUpdating = True

I wish to get rid of this flicker but still use ScreenUpdating .

Any ideas??

Regards, Omer.

1
Does it flicker once or does it keep flickering. Does the flicker stop? Also, I would suggest this has nothing to do with Python.Steven Rumbalski
for each time the above snippet is used it flickers once. it is a short flicker however since this code is used once per second it causes a flicker per second (no matter the size of the update). i'm sure it isn't related to python.omer bach
Once ScreenUpdating is reenabled, Excel redraws the screen. You cannot change that. Are you using Excel to display real time data? If so, you probably have the wrong tool for the job.Steven Rumbalski

1 Answers

0
votes

Some (if not all) Excel versions redraw themselves completely if you set ScreenUpdating=true. There is nothing you can do against it, I think.

You can, however, set ScreenUpdating to false and true conditionally. Often, one executes code that only sometimes (or rarely) really changes data. So if the sheet update you do in your code only occasionally really does updates, you could init a flag to false and then, set ScreenUpdating to false and the flag to true only if the code really makes an update. As the final step after the updates, set ScreenUpdating back to true only if the flag is set.

This way, you would only see flicker for the cases where there really was a data change. This already might be sufficient to get rid of the flicker effects most of the time.

To avoid that remaining flicker completely, you could try locking the Excel window's interior using Windows API functions, perform your code as outlined, and unlock afterwards. This would still create a flicker effect, but invisibly, since the redraw process does not show. Upon unlock, the redraw takes still place, but without clearing rectangle areas with the background color.