+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Forums Administrator royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    24,445

    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,

    Code:
    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 03:25 AM.
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel consulting, free examples and tutorials visit Excel Consulting-Excel VBA
    Check out the free Excel Toolbar

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)


    Code Tags: Make your code easier for us to read

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

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

  3. #3
    Forum Moderator shg's Avatar
    Join Date
    06-21-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007
    Posts
    25,134
    And to turn things off before executing user code?

  4. #4
    Forums Administrator royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    24,445
    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.
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel consulting, free examples and tutorials visit Excel Consulting-Excel VBA
    Check out the free Excel Toolbar

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)


    Code Tags: Make your code easier for us to read

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.2.0