+ Reply to Thread
Results 1 to 4 of 4

Application.ScreenUpdating

Hybrid View

  1. #1
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Application.ScreenUpdating

    Sometimes it is necessary in code to switch off ScreenUpdating to speed things up & prevent "screen flickers". It is also useful to switch off Calculation to speed things up.

    This code will capture the user's current settings & replstore them after the code has run,

    Option Explicit
    
    '---------------------------------------------------------------------------------------
    ' Procedure : myMacro
    ' DateTime  : 09/05/2008 08:56
    ' Author    : Roy Cox
    ' Website   : www.excel-it.com for more examples and Excel Consulting
    ' Purpose   : switch off application settings & restore after code has run
    ' Disclaimer; This code is offered as is with no guarantees. You may use it in your
    '             projects but please leave this header intact.
    
    '---------------------------------------------------------------------------------------
    '
    Sub myMacro()
        'declare boolean variables to store the user's settings
        Dim bScreenUpdating As Boolean
        Dim bDisplayAlerts As Boolean
        Dim bEnableEvents As Boolean
        Dim lCalculate As Long
        'set the variables
        With Application
            bScreenUpdating = .ScreenUpdating
            bDisplayAlerts = .DisplayAlerts
            bEnableEvents = .EnableEvents
            lCalculate = .Calculation
    
            'your code here
    
            'restore settings
            .ScreenUpdating = bScreenUpdating
           .DisplayAlerts = bDisplayAlerts
           .EnableEvents = bEnableEvents
            .Calculate = lCalculation
        End With
    
    End Sub
    Last edited by royUK; 05-16-2008 at 02:25 AM.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481
    Roy, you forgot to reverse the properties and variables when restoring you code.

            'your code here
    
            'restore settings
            .ScreenUpdating = bScreenUpdating
            .DisplayAlerts = bDisplayAlerts
            .EnableEvents = bEnableEvents
            .Calculation = lCalculate
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    And to turn things off before executing user code?

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Just checking if anyone read this(LOL)

    Thanks Andy & shg, I copied & pasted from the VBE & didn't notice that the second copy hadn't picked up.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1