+ Reply to Thread
Results 1 to 13 of 13

A function to replace all the application.screenupdating references

  1. #1
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    A function to replace all the application.screenupdating references

    Is there a method which could replace all of the numerous places in code in-which the code below is used? Maybe some type of function which is called instead of repeating the same code over and over or maybe this is the best method.

    Please Login or Register  to view this content.
    Edit: Sorry posted in the wrong forum
    Last edited by jeffreybrown; 03-12-2011 at 05:30 PM.
    HTH
    Regards, Jeff

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: A function to replace all the appliction.screenupdating references

    Jeff,

    You should be able to create a standard module and in it create a Public Sub with that code inside. You can then call that Sub from any worksheet within the workbook.

  3. #3
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: A function to replace all the appliction.screenupdating references

    Hi Paul,

    Since I am still learning the ropes of VBA, is this a good method or should you stick within each procedure or is it just preference?

  4. #4
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: A function to replace all the appliction.screenupdating references

    Generally if you repeat steps multiple times it is cleaner to have one instance of it, then call it when necessary. It does save a little memory. Normally it would be used for repetitive functions or more drawn-out code, but it will work in this instance just as in any other.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: A function to replace all the appliction.screenupdating references

    Maybe you could use somthing like this, Jeff. It maintains a stack of states so subs can push their desired state and then pop to return to the state when they were called. You can skip arguments that you don't care about.

    Minimally tested.

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: A function to replace all the appliction.screenupdating references

    Thanks Paul/shg,

    @shg...I couldn't quite get your code to cooperate but I will keep trying. In the meantime I have run across this...

    Please Login or Register  to view this content.
    So far with my testing I have not seen any problems but from your experience do you see this as a sound method?

    I got the idea from here

  7. #7
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: A function to replace all the appliction.screenupdating references

    Please Login or Register  to view this content.
    @shg, can you outline the use of VBA qualifier in the above ?

    I've seen Colin using the VBA qualifier of late and presume this is for good reason but have found little info. on it.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: A function to replace all the appliction.screenupdating references

    @ DO: VBA.Array always generates a zero-based array, even if the user has Option Base 1.

    @ Jeffrey: The potential problem is that (a) AppStateFalse always sets each of the properties "off" when that may not be exactly what you want, and (b) you must alternately call AppStateFalse and AppStateRestore or else you lose the state. Mine was intended to solve the case where nested subs may want to set their environment during execution and then restore it on return to the calling routine.

    Please Login or Register  to view this content.
    What problems are you having? As I said, it got only a two-minute test from me.
    Last edited by shg; 03-12-2011 at 05:13 PM.

  9. #9
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: A function to replace all the application.screenupdating references

    Hi shg,

    Chalk it up to being over tired last night. I was racking my brain trying to understand it and I was failing, but with your further explanation did the trick.

    What I was failing to do was actually change the attributes in the AppOnOff Push part.

    I set up a msgbox to display the status, TRUE/FALSE, and it is working fine. Thanks for you patience and instruction.

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: A function to replace all the application.screenupdating references

    Great!

    1. For consistency, and since there is no collision between vbUseDefault (=-2) and valid calculation states (-4135, -4105, and 2), I think the below is better.

    2. I changed it to a function, which returns True unless you try to Pop an empty collection.
    Please Login or Register  to view this content.
    For performance considerations, col would better be declared as a module-level variable rather than local and static, but I'm going to leave it as is.
    Last edited by shg; 03-12-2011 at 07:19 PM. Reason: Corrected error

  11. #11
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: A function to replace all the application.screenupdating references

    Hi again shg,

    No matter what combination I run for the AppOnOff Push, I get the MsgBox which says "Oops!". Any ideas why, but in the end everything is restored to the previous state.

  12. #12
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: A function to replace all the application.screenupdating references

    I trust you mean for Pop.

    Sorry, corrected in prior post.
    Last edited by shg; 03-12-2011 at 07:31 PM.

  13. #13
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: A function to replace all the application.screenupdating references

    Works grand

+ 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