Making an exact copy of a userform

mortgageman

Well-known Member
Joined
Jun 30, 2005
Messages
2,015
Is there a way to make a copy of an existing userform (with all its controls) into a new userform?

Gene, "The Mortgage Man", Klein
 

Some videos you may like

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
mortgageman,

this is my way:
create new workbook
goto VBA-Editor
drag form into new workbook project
change it's name
drag it back to original workbook

kind regards,
Erik
 

BJungheim

Well-known Member
Joined
Jul 24, 2004
Messages
914
You can Export the form, then rename it in the VBE and re-import it under the original name.
 

autigers

Board Regular
Joined
Oct 9, 2005
Messages
139
I have used the Export/ Import option with success
Right click the form from the project window (left side vb)
and choose export, save
then choose import by right clicking in same window ....
 
L

Legacy 98055

Guest

ADVERTISEMENT

You can also create as many instances of an object as you wish. For example, you have a userform named userform1...

Code:
Sub Example()
    Dim f1 As New UserForm1, f2 As New UserForm1
    
    f1.Show vbModeless
    f2.Show
End Sub

...will show two separate instances of userform1. Modeless only applies to office 2000 and up...

Tom
 

autigers

Board Regular
Joined
Oct 9, 2005
Messages
139
Hey Rightclick ...now thats a useful bit of info there !!!

Nice :biggrin:
 

mortgageman

Well-known Member
Joined
Jun 30, 2005
Messages
2,015
Right_Click: I tried using your idea in the following code - I want the "second" instance if the user right clicks. I got an error saying the the "top" needs to be closed first? Any ideas?

Gene, "The Mortgage Man", Klein

Private Sub OptionButton1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim f1 As New UserForm1
If Button = 1 Then
MsgBox "Your left click code goes here", , "Left button"
ElseIf Button = 2 Then
UserForm1.Hide
f1.Show
End If
End Sub
 
L

Legacy 98055

Guest
Hi Gene.

I'm not suggesting that you use the method I showed. It's just an option and usually better coding practice if you need two objects that vary little from one another. Also, I have never seen that error and would need to see more or perhaps all of the relevant code to understand what the problem is...

Tom
 

Watch MrExcel Video

Forum statistics

Threads
1,118,069
Messages
5,570,004
Members
412,304
Latest member
citrus
Top