Pausing a macro

B

brian

I have a workbook where I select a file to open, from a list on my
worksheet, and then I press a command button to open the file selected.
However when selecting the file, a calculation takes place and if I
press the command button before the calculation is finished, I get an
error message. If I could get about a 5 second pause after pressing
the command button, the calculation will then be finished before the
macro runs.

How do I do this?
 
B

Bob Phillips

Application.Wait(Now + TimeValue("0:00:5"))

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
H

Harald Staff

You don't say what kind of calculations or why it is trigged by the
selection how, but try something like

Private Sub CommandButton1_Click()
Application.Calculate
DoEvents
'rest of code here
End Sub

HTH. Best wishes Harald
 
B

brian

Bob Phillips solution resolves the problem. Thank for the help and to
all who replied.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top