0

so basically I need to pause the macro code, wait for user input and then continue the rest of the code. I know that by using the "modeless userform", this can be done. But the point now is that all the code after the userform popped up needed to written in the command button part (basically it is the userform own module). And because of that, all the initialization, all the variables that I still need has been wiped off.

So I am asking is there a way to pause in the middle of a vba code then, wait for user input, then continue the rest of the code

Thank you very much for your help

1 Answer 1

1

What do you mean as "user input"?

  • Standard input methods as MsgBox, InputBox or modal user forms do what you are asking;

"code after the userform popped up needed to"...

  • Instead of closing a form, hide it. Code continues and form data still available;

Now, if you mean by "user input", manipulating workbook, you must go on events:

  • Example: Create a before user input macro and then place remaining code in a Worksheet_Change event.
Sign up to request clarification or add additional context in comments.

2 Comments

It means the second one, to manipulate the workbook, put in column, add new workbooks kind of things. I understand that you want to separate the code into 2 part, but the point is all variables, all the values will have to be declared again or being pushed down by the first part. What's more is that you need to run 2 macro instead of 1, which is not exactly good for automation. And if there are more part which needs to be paused then there will be more code needed
This is also question of paradigm: VBA is a event driven language. Keep this in mind! Otherwise, how would you control user actions? Imagine user deletes a worksheet with your code, ...

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.