Hi BryceVBA,
There are several methods that can be used to do what you want including:
a. API (Application Programming Interfaces) Sleep routine (my first choice)
b. Application.OnTime
c. Application.Wait
d. API Timer routines
I prefer the Sleep routine because it is:
a. relatively simple to use and plays nicely with others
b. allows access to Excel while waiting (not needed in this application)
In cases where I need access to Excel, I usually set the repeat rate at 200 or 250 Milliseconds (about 0.2 or 0.25 seconds).
See the attached file which contains the following code that has the capability of:
a. Creating Scratch file zyx.xlsx in the same folder as the file running the code.
b. Deleting file zyx.xlsx
c. Waiting for file zyx.xlsx to exist or timeout
It is a best practice to declare all variables. If you misspell a variable in your code, VBA will silently assume it is a Variant variable and go on executing with no clue to you that you have a bug. Go to the VBA development window, click Tools, Options, and check "Require Variable Declaration." This will insert the following line at the top of all new modules:
This option requires all variables to be declared and will give a compiler error for undeclared variables.
Lewis
Bookmarks