Excel VBA make a script asynchronous

后端 未结 3 1660
忘了有多久
忘了有多久 2021-01-18 06:05

I have a script that can ping a list of computers and change their background color depending after the result it gets.

My problem is, that it blocks the entire exce

相关标签:
3条回答
  • 2021-01-18 06:23

    You can't do too much about this unfortunately since VBA runs in a single thread.

    You can however introduce a degree of responsiveness by putting

    VBA.DoEvents()
    

    in various places in your code, ideally in the tight loops. In your case, put them just after the lines containing For. This pauses the VBA and flushes the event queue which will have the effect of making Excel responsive.

    (Toggling the screen updating is a bad idea since you might leave things in a bad state if the function terminates unexpectedly. I'd remove the lines that do that if I were you.)

    0 讨论(0)
  • 2021-01-18 06:30

    While strictly speaking you cannot make Excel to behave as you need, there is a trick to work around it. The solution is to create another Excel instance. Then you can run the macro in one of the instances and work independently in the other one. You can open another Excel instance from the Run prompt (press Windows + R) and then type Excel /x, then Enter

    0 讨论(0)
  • 2021-01-18 06:41

    Excel can calculate "asynchronously". Call sPing as a function.

    I'm not sure why your range is A1:N50. I assume one of the columns is the IP address, which I will assume as A. So your formula in column M will look like =sPing(A1).

    As for the color coding, you can use conditional formatting.

    0 讨论(0)
提交回复
热议问题