Solved

Odd ScreenUpdating=False Problem

Posted on 2014-09-25
8
127 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 32

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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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 32

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
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…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

776 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