View Full Version : Solved: Programically Nested Multipages
Treygor
11-03-2006, 10:05 AM
I need to have 2 multipages nested and on the 2nd Multipage, I want to programically add in a listbox. Here is the code I have:
Sub Set_Page_Topics()
Dim I, II As Integer
Dim NewMPage As MSForms.MultiPage 'allows me to name the dynamically created 2nd multipage set
I = 1
UserForm1.MultiPage1.Pages.Clear 'Initialize the multipage to have zero pages to start.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Adds the topics to the multipage.
'Topics must be placed on sheet 1, in consecutive cells
Do While Sheet1.Cells(1, I) > ""
UserForm1.MultiPage1.Pages.Add Sheet1.Cells(1, I).Text
II = 2
With UserForm1.MultiPage1.Pages(I - 1)
Set NewMPage = .Controls.Add("Forms.Multipage.1") 'adds dynamic mulitpage to every page in multipage1
NewMPage.Pages.Clear
NewMPage.Height = 250
NewMPage.Width = 450
Do While Sheet1.Cells(II, I) > "" 'Names each dynamically created multipage sheet
NewMPage.Pages.Add Sheet1.Cells(II, I)
II = II + 1 'Counter
Loop
End With
I = I + 1 'Counter
Loop
End Sub
How do I get the listbox to programically go into the 2nd Multipage? I have tried the code below but it won't work. Can someone help????!
With NewMpage.Pages(I-1)
.Controls.Add ("Forms.LIstbox.1")
End With
Norie
11-03-2006, 10:21 AM
That code does add a listbox, but I don't know if it's being added where you want it.
Treygor
11-03-2006, 10:26 AM
When I run the code I get an Error. It states "Invalid Procedure Call or Argument." I am not sure what to do. Let me know if you have any ideas.
Norie
11-03-2006, 10:40 AM
Where have you actually placed that piece of code?
It doesn't appear in the initial code.
Treygor
11-03-2006, 11:04 AM
Here is the full code
Sub Set_Page_Topics()
Dim I, II As Integer
Dim NewMPage As MSForms.MultiPage 'allows me to name the dynamically created 2nd multipage set
I = 1
UserForm1.MultiPage1.Pages.Clear 'Initialize the multipage to have zero pages to start.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Adds the topics to the multipage.
'Topics must be placed on sheet 1, in consecutive cells
Do While Sheet1.Cells(1, I) > ""
UserForm1.MultiPage1.Pages.Add Sheet1.Cells(1, I).Text
II = 2
With UserForm1.MultiPage1.Pages(I - 1)
Set NewMPage = .Controls.Add("Forms.Multipage.1") 'adds dynamic mulitpage to every page in multipage1
NewMPage.Pages.Clear
NewMPage.Height = 250
NewMPage.Width = 450
With NewMpage.Pages(I-1)
.Controls.Add ("Forms.LIstbox.1")
End With
Do While Sheet1.Cells(II, I) > "" 'Names each dynamically created multipage sheet
NewMPage.Pages.Add Sheet1.Cells(II, I)
II = II + 1 'Counter
Loop
End With
I = I + 1 'Counter
Loop
End Sub
Ken Puls
11-03-2006, 02:36 PM
Did you want to add a listbox to each page in the nested mutlipage? Or just the second page of the multipage?
Your issue currently is that you are trying to create a listbox on your multipage which has no pages on it...
This will add a listbox to each nested multipage page:
Sub Set_Page_Topics()
Dim I, II As Integer
Dim NewMPage As MSForms.MultiPage 'allows me to name the dynamically created 2nd multipage set
I = 1
UserForm1.MultiPage1.Pages.Clear 'Initialize the multipage to have zero pages to start.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Adds the topics to the multipage.
'Topics must be placed on sheet 1, in consecutive cells
Do While Sheet1.Cells(1, I) > ""
UserForm1.MultiPage1.Pages.Add Sheet1.Cells(1, I).Text
II = 2
With UserForm1.MultiPage1.Pages(I - 1)
Set NewMPage = .Controls.Add("Forms.Multipage.1") 'adds dynamic mulitpage to every page in multipage1
NewMPage.Pages.Clear
NewMPage.Height = 250
NewMPage.Width = 450
Do While Sheet1.Cells(II, I) > "" 'Names each dynamically created multipage sheet
With NewMPage.Pages.Add
.Caption = Sheet1.Cells(II, I)
.Controls.Add ("Forms.LIstbox.1")
End With
II = II + 1 'Counter
Loop
End With
I = I + 1 'Counter
Loop
End Sub
Treygor
11-04-2006, 11:39 AM
That fixed the problem!!! Thanks a ton for the help!
This Procedure is really confusing to this Noob. :banghead: :banghead: :banghead: :dunno
According to Excels VB Help;
Multipage Control:
The MultiPage is a container of a Pages collection, each of which contains one or more Page object
Pages Collection:
A Pages collection includes all the pages of a MultiPage.
Clear Method:
For a MultiPage or TabStrip, the Clear method deletes individual pages or tabs.
Add Method:
Adds or inserts a Tab or Page in a TabStrip or MultiPage, ... to a page or form.
Dim NewMPage As MSForms.MultiPage 'Create new Variable; NewMpage
I = 1
UserForm1.MultiPage1.Pages.Clear 'Remove all page's from UF1's MP1(named Control)Pages
'Collection.
Do While Sheet1.Cells(1, I) > ""
UserForm1.MultiPage1.Pages.Add Sheet1.Cells(1, I).Text 'Put many new Page's
'(Named "Text" Value)
'in UF1's MP1. Shouldn't
'"Sheet1.Cells.Etc" Be enclosed
'in Parens()?
II = 2
With UserForm1.MultiPage1.Pages(I - 1) 'With each Page in UF1's MP1
Set NewMPage = .Controls.Add("Forms.Multipage.1") 'Add New MultiPage Control
'with system generated Names?
NewMPage.Pages.Clear 'Remove all Page's from what? NewMpage or all the new
'Controls we just made? Or is this a Dead function?
'Set NewMpage's size and add Page's to it.
'What are all the NewMPage Methods woking on??????
End Sub
SamT
Ken Puls
11-06-2006, 09:54 AM
Sorry, Sam, I'm not really following your question here..?
Ken,
Thanks for your attention. I think that I don't understand the above code well enough to formulate a coherent question.
Yet.
By the time I do, I probably won't need to ask, so I'm willing to drop the subject if you are.
SamT
Ken Puls
11-07-2006, 09:14 AM
Hi Sam,
We don't have to drop it if you want to understand it. I don't mind taking the time to explain.
Was your question really based around why the arguments for the first multipage creation were not in parens() and the second was?
Ken,
Actually, it was the Add Method syntax that was putting me in a loop. I didn't even recognise it as a method...Duh.
I put in about 4 hours today working on putting the MS Forms Object Model onto a worksheet. Plus putting the help pages of all the Events, Collections, methods, and Properties into the Title Cells' comments sections.
No. I did not read all of them. Well maybe I did, 'cuz there is a lot of stuff ya gotta know just to decide what belongs to what parent.
Anyway, now I can at least put the words on a map.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.