PDA

View Full Version : Dynamically Duplicating a Page within a Multi-Page UserForm



eemiller1997
11-28-2012, 09:11 AM
I have a multi-page userform. Currently, it’s three pages. I need to create a field where the user can input a number and it will do the following:

1. Duplicate page 3 of the Multi-Page UserForm that many times.
2. Duplicate the excel worksheet that same number of times.

I have found the following code that works for part of Step 2. But, I still need to work out having it repeat as many times as requested by the user.



Sub CopyWorksheet()
Sheets("Candidate (1)").Select
Sheets("Candidate").Copy After:=Sheets(Sheets.Count)
Sheets("Values").Select
Sheets("Values").Move After:=Sheets(Sheets.Count)
End Sub


I have found online the following code should duplicate a page, but it’s not working.



Set M = IntvwWorksheet.Pages.Add("Candidate2", "Candidate 2", 4)


Can someone please help me with this. I have nearly finished everything about this UserForm except this part and I desperately need to get it figured out.

I appreciate your help!

CodeNinja
11-28-2012, 02:57 PM
eemiller1997,
You can use (userform name).(multipage name).pages.add(Name of page) and add any controls to the page with pages(index).controls.add type, name

That would look like this:
Private Sub CommandButton1_Click()
Static i As Integer
UserForm1.MultiPage1.Pages.Add ("Page " & 3 + i)
i = i + 1
UserForm1.MultiPage1.Pages(2).Controls.Add "Forms.TextBox.1", "TextBox 1", True
End Sub