I'm working on a little Excel-VBA GUI/Form for the user to read and write data from/to an .ini file. The UserForm has a MultiPage in which the user creates pages at runtime and each page will represent an ini section. Furthermore, these sections are also indexed in a master section for further processing: at this point I'm looping through the MultiPage pages to create this index. Problem is, the user needs to be able to change the order of this index. Now, is it possible to move the pages within a MultiPage at runtime? I was thinking something to the effect of
Me.MultiPage1.Pages(i).Index = i + 1
but obviously that doesn't work. Alternatively, is there a way I can pass a before:= or anything similar to Multipage.Pages.Add to work around it? If none of this works, I think I'll create a seperate ListBox control with MoveUp/Down buttons. Open for any better solutions.
For anybody looking for this in the future, here's the complete solution using Robin's code (Thanks!), but put in a Class for the pages created at runtime. I'm only pasting the relevant code to this question, the CopyPage procedure can also be called by the user to add pages during runtime. Now the user can also move them left and right between pages 2 (index 1) and n.
In my main module:
In my CButton Class Module:
And my UserForm_Initialize:
Yet in another standard module, so it can be called from elsewhere too:
Say you have a
UserForm
that looks like this:Then you can include the sample code below to move the order of the
Page
items of theMultiPage
: