+ Reply to Thread
Results 1 to 6 of 6

Set priority in VBA

  1. #1
    Forum Contributor
    Join Date
    07-08-2008
    Location
    New York City
    MS-Off Ver
    2013-2016
    Posts
    159

    Set priority in VBA

    Hello,

    Is there a way to set priority of a sub or procedure in VBA? I'm not refering to the VBA project priority.

    For example, if I have a sub running in a loop in the background and I want to give priority to that over everything else.
    It happens sometimes that the background process stutters while doing something else.

    Not sure if possible, but I may as well ask to make sure.

    Thank you.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner VA USA
    MS-Off Ver
    MS 365 Family 64-bit 2505
    Posts
    27,458

    Re: Set priority in VBA

    What do you mean by "background", what do you mean by "everything else", and what you do mean by "stutters"? When VBA runs it is the Excel process thread; it's not a background process. It sounds like you need to set the priority of the Excel instance in the Windows process list.

    If it sounds like I don't understand what you want then maybe explain a little further in concrete terms what you are trying to do.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Contributor
    Join Date
    07-08-2008
    Location
    New York City
    MS-Off Ver
    2013-2016
    Posts
    159

    Re: Set priority in VBA

    Sorry if I didn't use the correct lingo. I'm not a professional programmer.

    Instead of "background" then let's say "at the same time", "Everything else" --> "other procedures", and by "stutters" I meant data that should refresh after a specific interval, doesn't. In this case the system's time (seconds skipping when other subs executing).

    I was wondering if there was a way to specify priority for a sub over the rest. At this point I think the answer is no.

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner VA USA
    MS-Off Ver
    MS 365 Family 64-bit 2505
    Posts
    27,458

    Re: Set priority in VBA

    Terminology is not the issue. I am looking for a complete description of what you want to do. It doesn't matter what terms you use but I still don't understand what are the things happening at the same time here. Do you mean other Excel macros running at the same time? Only one macro thread can run at one time. Other Windows programs?

    Maybe it will help to say that you cannot specify a priority for a specific VBA sub. You can specify priorities for Windows services (see screen shot below), but I am not getting the sense that's what you need.

    If you provide your file and explain what it does, we can probably solve your ultimate problem. If you have a Sleep or a timer in your code, it is not guaranteed to stop at the exact instance you have specified. It is only guaranteed to stop as soon after that instant as the system can do. This almost always happens right on time but if the system is busy it will be late. If you are experiencing cumulative time lags (e.g., you want to wait 5 seconds but it waits 6 seconds, 7 seconds, and you get more and more behind schedule) then we can reprogram so you have jitter (each individual interval might be off but we remove the overall cumulative delay).

    It just depends on the practicality of what you are trying to do. I'm willing to help if you want to describe your overall problem.

    service priority.jpg

  5. #5
    Forum Contributor
    Join Date
    07-08-2008
    Location
    New York City
    MS-Off Ver
    2013-2016
    Posts
    159

    Re: Set priority in VBA

    Thanks. My question was macro-related and nothing to do with Windows processes, which i'm familiar with.

    You answered my question here: "Only one macro thread can run at one time".
    My understanding was that if I had set up a timer for a macro, the time specified to run it would be respected, even if it meant running simultaneously with another macro. I see that isn't the case.

    Thank you for the detailed explanation.

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner VA USA
    MS-Off Ver
    MS 365 Family 64-bit 2505
    Posts
    27,458

    Re: Set priority in VBA

    Here is a demo. Run the sub OngoingAction. It sets a timer for 30 seconds. When the timer goes off it will put a message on the sheet. In the meantime, the sub will loop for 60 seconds showing a countdown then stops. You will see that even though the timer is set for 30 seconds, it can't run until the 60-second countdown finishes.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Priority Scheduling
    By KiwiMatt in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-22-2021, 08:20 PM
  2. Priority for rows
    By Robert A in forum Excel General
    Replies: 1
    Last Post: 10-22-2017, 06:56 AM
  3. [SOLVED] Priority tagging
    By deanblew in forum Excel General
    Replies: 7
    Last Post: 07-28-2017, 06:27 AM
  4. Replies: 2
    Last Post: 05-10-2017, 07:32 PM
  5. Replies: 10
    Last Post: 01-09-2015, 04:40 PM
  6. Copy Priority
    By the.white.hole in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-09-2011, 11:45 AM

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