Excel stalls after 7-8 VBA subs are called in a row

BetterBeef

New Member
Joined
Mar 18, 2010
Messages
42
I have a sub in Excel which calls 12 other subs from within my current VBA code. These subs are called right in a row. However, once the 7th or 8th sub is called, Excel freezes and I have to go into Task Manager and manually close out Excel. If I try this again, I get the same result.

Is there something I need to do (like add a pause) to allow for all 12 subs to run correctly?

Thanks,
Chris V.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Sounds more like an issue w/ your macro and not the # of macros. can you run them individually without issue?
 
Upvote 0
My macro works fine. I can run up to 5 of the macros with no problems. 12 is just too much. Running each macro separately runs without a hitch. Note: I am also running Excel 2010.
 
Upvote 0
Using the following formula, I was able to get it to work.

Sub Wait(tSecs As Single)
' Timer to create a pause
Dim sngSec As Single

sngSec = Timer + tSecs
Do While Timer < sngSec
DoEvents
Loop
End Sub

I use this wait function every 4 or 5 functions that I call (wait for one second), and I do not have any problems. I still don't understand why this is a problem. In theory I should be able to call an infinite number of subs without needing a pause. If anyone has an answer to this, I would love to know!
 
Upvote 0
Chris

What do the macros do?

Can you post any of the code?

Have you tested running only one of them, then running 2 of them, then 3 of them and so on?

That might give you some idea if it's one particular sub/macro that's causing the problem.
 
Upvote 0
As I said before, all my code runs fine. There just seems to need to be a pause of some sort for everything to run correctly.
 
Upvote 0
The only thing I would like to add is that each macro that I have basically pulls a report from the web (.txt file), and parses it out for user readability. I don't know if going to the web is the reason I need the pauses or not.
 
Upvote 0
If you need to pause there must be something in the code you need to pause for.

There might be some other way to deal with it, there might not - perhaps you could use Application.Wait

Anyway, looks like you found a solution.:)
 
Upvote 0
If there are points at which you are changing stuff that requires recalculation, and then require the results of that calculation to continue, then you could instead use

Code:
    Calculate 
    Do Until Application.CalculationState = xlDone
        DoEvents
    Loop

To Norie's point, knowing when the process dies would help in understanding the issue. You could send progress messages to the Immediate window and see how far things get before it goes Tango Uniform.
 
Upvote 0
Actually, if you are getting data from the web there might be other ways to deal with the pause.

That would depend on what method you were using for that part of the process.
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top