Adding code to a programmatically created userform CodeModule

ksheehan1511

New Member
Joined
Aug 17, 2012
Messages
1
I'm having trouble finding a simple (relatively so) way to add a huge chunk of code I already wrote for a previous userform to a userform that is programmatically created. The userform has a set of OptionButtons, some TextBoxes, and CheckBoxes. I previously created a userform the normal way and coded for all the event procedures in its CodeModule but now that I have a sub procedure create a userform, I want a way to use most of the code from the previous form. The only way I can find to add code to a CodeModule in the userform creation sub is to use the .CodeModule.InsertLines member and this seems very tedious as it will require me to retype everything line by line.

My question is: Is there a way around doing it this way? The reason I don't have a simple few lines calling another sub is because I have "If Option[blank] Then" commands that operate on OptionButton events and calling out to another procedure comes up with "variable undefined" errors.

Thanks!
 
Last edited:

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hi
Welcome to the board

I'd like to say first that I don't like the idea of creating the form from code at execution time. I'd have the form (or more than one) already created, even if necessary with some redundant objects that I could hide to adapt to the dynamic needs.

... I want a way to use most of the code from the previous form. The only way I can find to add code to a CodeModule in the userform creation sub is to use the .CodeModule.InsertLines member and this seems very tedious as it will require me to retype everything line by line.

My question is: Is there a way around doing it this way? ...

If I understand correctly you want to copy some (or part) of the code of an existing module to another one. Can you not just use the respective CodeModule objects and copy from one to the other?
 
Upvote 0

Forum statistics

Threads
1,213,515
Messages
6,114,080
Members
448,548
Latest member
harryls

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