3

I need to find the VBA code to add x number of tabs to a multipage in a userform in excel. I can manually add tabs if I use the visual basic editor, but I want to be able to dynamically add/delete tabs using VBA during runtime.

Thanks

Siddharth Rout
  • 147,039
  • 17
  • 206
  • 250
Ehudz
  • 613
  • 10
  • 22
  • 33

2 Answers2

3

The Tabs in a MultiPage1 are called Pages and you can add them using

MultiPage1.Pages.Add

You can use the above code in a loop to add pages. Please refer to Excel's inbuilt help for more details

Edit:

Just saw the 2nd part of the question. To delete, say the 1st page use this

MultiPage1.Pages.Remove (0)
Siddharth Rout
  • 147,039
  • 17
  • 206
  • 250
2

You can add/remove them dymanically to the form permanently with

Sub Test()
Dim vbComp As Object
Dim objCntrl As Control
Set vbComp = ThisWorkbook.VBProject.VBComponents("UserForm1")
Set objCntrl = vbComp.Designer.Controls("MultiPage1")
'add page
objCntrl.Pages.Add
'remove page
objCntrl.Pages.Remove (1)
End Sub
brettdj
  • 54,857
  • 16
  • 114
  • 177