View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Harald Staff Harald Staff is offline
external usenet poster
 
Posts: 1,327
Default duplicate a user form?

"Pal" skrev i melding
news:DWUjc.8038$RE1.813063@attbi_s54...
Is it possible to duplicate a user form?
I have one that I want to use twice with only a slight modification.


Hi Pal

Welcome tho the world of classes and objects. Plan a form flexible enough
and you can use it for infinite variations.

In an empty workbook, create one single Userform1 with CommandButton1 and
CommandButton2. Then in a standard module paste and run this:

Sub ThreeForms()
Dim U1 As UserForm1
Dim U2 As UserForm1
Dim U3 As UserForm1

Set U1 = New UserForm1
U1.BackColor = RGB(0, 0, 255)
U1.CommandButton1.Caption = "Yo da man !"
U1.CommandButton1.Top = U1.Height / 2 - _
U1.CommandButton1.Height / 2
U1.CommandButton1.Left = U1.Width / 2 - _
U1.CommandButton1.Width / 2
U1.CommandButton2.Visible = False
U1.Caption = "Yo da man ?"

Set U2 = New UserForm1
U2.BackColor = RGB(210, 255, 175)
U2.CommandButton1.Caption = "Absolutely"
U2.CommandButton2.Caption = "Neat !"
U2.Caption = "Beauty contest"

Set U3 = New UserForm1
U3.BackColor = RGB(255, 255, 0)
U3.CommandButton1.Caption = "Abort"
U3.CommandButton1.BackColor = RGB(255, 0, 0)
U3.CommandButton1.Top = 3
U3.CommandButton1.Left = 6
U3.CommandButton2.Top = 25
U3.CommandButton2.Left = 6
U3.CommandButton2.Caption = "Cancel"
U3.CommandButton2.BackColor = RGB(255, 0, 0)
U3.Caption = "Install Windows XP"

U1.Show
U2.Show
U3.Show

End Sub

HTH. Best wishes Harald