简体   繁体   中英

VBA Excel Dynamic Form Creation

Question: I have a form I created in Excel (Developer mode). The form has a MutliPage control on it. I am able to add a dynamically add new Page to the multipage control with VBA. I have no idea how to add any content onto this page that I have just created - for example adding a new checkbox, labels etc.

The only code I have at the moment is:

DataQueryForm.DimensionTabs.Pages.Add "MyName", "My Caption"
Dim currentPage As Page
Set currentPage = DataQueryForm.DimensionTabs.Pages(0) 'this line fails

As you can see I don't even know how to get the first Page into a variable of type Page - so it's hard to know how to begin.

Any pointers in how to add new checkboxes to the page would be most appreciated. I'm really struggling to find decent documentation on this, really, anything at this stage would be helpful.

Thanks

You need to specify MSForms.Page so you don't get a type mismatch (Excel also has a Page object) and you can set the variable as you add the page:

Dim currentPage As MSForms.Page
Set currentPage = DataQueryForm.Dimensiontabs.Pages.Add("MyName", "My Caption")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM