Solved

Odd ScreenUpdating=False Problem

Posted on 2014-09-25
8
132 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 47

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 47

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 47

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 47

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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

734 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