Excel VBA make a script asynchronous

后端 未结 3 1662
忘了有多久
忘了有多久 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.)

提交回复
热议问题