1

I write chemical plant simulations in VBA for Excel. I currently use the Application.OnTime method to delay for 1 second. The simulation procedure runs each second. This allows me to change values in the spreadsheet and do other things on the computer while the simulation is running.

However, I would like to run the simulation procedure faster than 1 second. Application.wait prevents me from doing anything else to the spreadsheet while waiting.

JohnS
  • 11
  • 1

2 Answers2

0

You can try using the DoEvents function which yields execution. This allows you to perform tasks while the process runs and counts in the background. Couple this with a Timer function which yields milliseconds (at least on Windows, MAC resolution is 1s).

Perfect example in the official docs: https://msdn.microsoft.com/en-us/library/office/gg264522.aspx

M. Wicha
  • 1
  • 3
0

You will need to use the Sleep API for intervals less than a second as shown in this post:

https://stackoverflow.com/a/18603933/5162073

As mentioned by @MWicha, you can also use DoEvents to yield execution if needed.

Brian M Stafford
  • 8,483
  • 2
  • 16
  • 25