Solved

Odd ScreenUpdating=False Problem

Posted on 2014-09-25
8
131 Views
Last Modified: 2014-10-01
Hi Experts, I'm in excel 2007 experiencing a weird issue.
Please open the attached workbook.

Please try clicking any of the navigation buttons. You'll see that as you navigate between sheets a box will appear highlighting the used range before switching worksheets. That is because of the following code to set the zoom on each sheet:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
'set zoom for active sheet to columns with data
 ActiveSheet.UsedRange.Resize(ActiveSheet.UsedRange.Columns.Count).Select
 ActiveWindow.Zoom = True: ActiveWindow.VisibleRange(1, 1).Select
End Sub

Open in new window

Now what's odd is that on Workbook_Open I have set ScreenUpdating equal to false see the below code:
Private Sub Workbook_Open()
Application.ScreenUpdating = False
Call FormatWorkbook
'activate StandardMode
Sheets("StandardMode").Activate
End Sub

Open in new window

I've discovered that if I add another Application.ScreenUpdating = False statement to the zoom code it will work....... but why would I have to set it to false twice? Is it being set to true after Workbook Open somehow?
EESafe-UI-Input-09.24.xlsm
0
Comment
Question by:-Polak
  • 4
  • 2
  • 2
8 Comments
 
LVL 46

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 40344291
It's a quirk but ScreenUpdating always sets itself to True at the and of any routine.
0
 
LVL 46

Assisted Solution

by:Martin Liss
Martin Liss earned 500 total points
ID: 40344298
And you can prove it by creating these two macros. Run x and then run y.
Sub x()
Application.ScreenUpdating = False
End Sub

Sub y()
MsgBox Application.ScreenUpdating
End Sub

Open in new window

0
 
LVL 33

Expert Comment

by:Rob Henson
ID: 40344304
Does that mean you don't have to consciously put:

Application.ScreenUpdating = True

At the end of a routine?

Thanks
Rob H
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 46

Expert Comment

by:Martin Liss
ID: 40344318
That's correct, but I do it anyhow for clarity.
0
 
LVL 1

Author Closing Comment

by:-Polak
ID: 40344352
Well alrighty then!
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40344368
I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
0
 
LVL 33

Expert Comment

by:Rob Henson
ID: 40344387
I guess I am thinking of times when I have included a Stop command in the script so have then had to manually reset the Screen Update to True
0
 
LVL 1

Author Comment

by:-Polak
ID: 40354923
Hey guys, just a heads up on this, while it does seem to set itself back to true in every other circumstance; if you don't have it set to true at the end of a subroutine and then insert another worksheet it will appear as if excel has frozen. (this was excel 2007)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question