7

In Excel VBA, I want to push a button, run some code, and while the code is running have a form window appear saying something like "Code is running, please wait until finished. Click stop button to terminate code."

But every time I .Show a form the code stops, waiting for the form window to be closed before continuing. Is there a way to force the code to continue to run while the form window is open? Thanks!

Answered: Add (False) at the end of .Show or change the form's ShowModal property to False. Then add Application.Wait (Now + TimeValue("0:00:01")) just after fmRunning.Show(False). Or insert "DoEvents" instead of the Application.Wait Thanks all!!

11
  • 4
    Show the form without making it modal UserForm1.Show(False) Commented Feb 18, 2016 at 14:48
  • 1
    Thanks for the suggestion, but when I do that the form appears blank and unresponsive. Is there something else I have to do? Commented Feb 18, 2016 at 15:05
  • 1
    try putting a DoEvents after calling the userform. Commented Feb 18, 2016 at 15:07
  • Damn @Scott is fast. :) Commented Feb 18, 2016 at 15:08
  • I added DoEvents, I get the same problem except now the window doesn't close at the end of the code like it used to, but at least after the code is done the form populates with text (#trolledByCode). Here is how I have it: Sub codename() DoEvents fmRunning.Show(False) 'I have also tried it without the false and 'instead with vbModeless and another time setting it's properties to 0. ... ... fmRunning.Close End Sub Commented Feb 18, 2016 at 15:18

4 Answers 4

9

You need to set the userform to be modeless. This can be done two ways:

  • either by selecting the userform and changing the ShowModal property to False
  • or by opening the userform with setting the modal property to 0 (vbModeless)
Userform.Show vbModeless

See MSDN for more info.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the suggestions, but when I do either of those the form appears blank and unresponsive. Is there something else I have to do?
1

Using only Userform.Show vbModeless can cause blank form. You should also use the command Userform.Repaint. This will refresh the info on the form. Example:

Userform.Show vbModeless
Userform.Caption = "Some text"   'change the Caption text
Userform.Repaint   'refresh changes

This way you should see the changes

Comments

0
  1. Select the form in the Project panel.
  2. Change the ShowModal to false

this will keep your code running even the form is opned

enter image description here

Comments

0

If all you are doing is advising the user to wait then you don't need an extra form. Simply add a label to the form that say "Please wait...". Set the label as hidden until the button is pressed then make it visible at the start of the code and hide it again when the code finishes. You might need to insert DoEvents straight after the visible = True instruction as it might be overtaken by the main section of code.

me.label1.visible = true/false

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.