Dynamically Adding a ComboBox to a Page on a userform

shennricks

New Member
Joined
Apr 1, 2022
Messages
9
Office Version
  1. 365
Platform
  1. Windows
I'm trying to create code that adds a combobox to a multipage on a userform. I've tried copied examples I am seeing online but getting an error:

Dim newTextBox
Dim MyPage
Dim MultiPage1

Set MyPage = Item.GetInspector.ModifiedFormPages("P.2")
Set MultiPage1 = MyPage.MultiPage1

Set newTextBox = MultiPage1.Pages("Chamber 1").Controls.Add("Forms.TextBox.1", 1)


When I get to the 'Set MyPage line I'm getting an error saying that variable is not found for 'Item'. Not seeing in the examples where this is supposed to be defined. I'm not entirely sure what is going on with this piece of code.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Try this:
VBA Code:
    Dim cb As ComboBox

    With Me.MultiPage1.Pages(1)  'page 2
        Set cb = .Controls.Add("Forms.ComboBox.1")
        With cb
            .Top = 5
            .Left = 5
            .Height = 15
            .Width = 100
        End With
    End With
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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