Multithreading Tool – Threads

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

Is there a way code the number of threads to automatically use the maximum number available rather than hardcoding how many you want it to use?


Answered question

Hi, there is no limit to the number of threads you can create. In majority of cases the suggested limit is the number of logical cores your CPU has, however, even this will depend on the algorithm you are implementing.

In the VBA Web Scraping Multithreading example based on Daniel Ferry’s example each thread waits for a HTTP response hence adding more threads than logical cores might make sense.

If you want to hardcode the suggestion of using the number of logical cores check my WMI post.

Posted new comment

This is awesome. Thanks! Do you know why when I try to download the sample it says the file extension is wrong?

Do you have any ideas on how you can track progress with multithreading with vba via vbs? In other words, if you’re running 4 threads do you know of a way to look at the numbers of iterations completed across all threads over the total number of iterations (i.e. % complete)?


I tried Chip Pearsons hidden name solution here:

Unfortunately, it seems like when this is called from the VBS worker threads it breaks.

Tom (AnalystCave)

There are many ways of tracking progress. But none will be as straight forward probably as you would like. I can think of a few ways:
1. Create files with progress status – just save your progress to each file as a % or even save progress messages. You can also log all your progress using my VBA Error Logger:
2. You can try saving your progress to the master file like so: using the arallelMethods.SaveRangeToMaster. However, don’t overdo it as again the application might crash if there are too many concurrent saves or slow down :).

Simply the best place to learn Excel VBA