0

I created a user form that asks the user to fill in 3 parameters (textbox) + having OK button.

I also have a sub procedure, public sub Analyze (actionName as String, endStr as String, startStr as String) which I call with different parameters.

I wish that upon clicking on Ok button on my user form, a new button will be created (this can easily be done by activesheet.buttons.add) and will be assigned to a new macro - the Analyze procedure with the parameters from the user form --> so i need to create each time a new sub calling Analyze sub with different parameters.

Is it possible? how can I do that?

user3121718
  • 33
  • 1
  • 8
  • 1
    Possible duplicate of [How to add a command button in VBA?](https://stackoverflow.com/questions/31684157/how-to-add-a-command-button-in-vba) – Pᴇʜ May 09 '18 at 08:42
  • nope, it explains how to create a button and assign it to a macro - this i know. My problem is that my sub is dynamic, i wish to call it with different input parameters, taken from my user form. – user3121718 May 09 '18 at 08:54
  • A button can only call a sub without parameters. So probably better save these parameters in a sheet and use them from there? – Pᴇʜ May 09 '18 at 08:58
  • I'm able to save them to the sheet, did that. But how can i create now new macro calling Analyze with those parameters? – user3121718 May 09 '18 at 09:01
  • Eg if you have a button on each row of parameters you can link all buttons with the same procedure and use `ActiveSheet.Shapes(Application.Caller).TopLeftCell.Row` to get the row of the clicked button and read the parameters from this row then. – Pᴇʜ May 09 '18 at 09:05
  • maybe. but i'm looking for something cleaner. maybe this will help, will try: https://stackoverflow.com/questions/29858176/how-to-call-a-macro-from-a-button-and-pass-arguments – user3121718 May 09 '18 at 09:11

0 Answers0