Hi!
Im currently working in excel 2003.
I have made a program that, reads cells from a
list. Look below for the code, its very very basic, but works I will be adding stuff once i get this part done.
As you can se when i double click the listbox a new page is created with a number from the listbox.
MY QUESTION: is there by any chance a way to add a page, and also include controls liek textboxt boxes. Like creating a template that get loaded everytime a new page is created. You must be able to have multiple pages open, so i imagine that the controls must have a coutner not to get namned the same.
Im currently working in excel 2003.
I have made a program that, reads cells from a
list. Look below for the code, its very very basic, but works I will be adding stuff once i get this part done.
As you can se when i double click the listbox a new page is created with a number from the listbox.
MY QUESTION: is there by any chance a way to add a page, and also include controls liek textboxt boxes. Like creating a template that get loaded everytime a new page is created. You must be able to have multiple pages open, so i imagine that the controls must have a coutner not to get namned the same.
Code:
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
'MsgBox "DblClick"
Dim SourceRange As Excel.Range
Dim Val1 As String, Val2 As String, Val3 As String
If (ListBox1.RowSource <> vbNullString) Then
'Get Range that the ListBox is bound to
Set SourceRange = Range(ListBox1.RowSource)
Else
'Get first data row
Set SourceRange = Range("Sheet1!A2:C2")
Exit Sub
End If
Val1 = ListBox1.Value
'Get the value of the second column
Val2 = SourceRange.Offset(ListBox1.ListIndex, 1).Resize(1, 1).Value
'Get the value of the third column
Val3 = SourceRange.Offset(ListBox1.ListIndex, 2).Resize(1, 1).Value
Val1 = ListBox1.Value
'Get the value of the second column
Val2 = SourceRange.Offset(ListBox1.ListIndex, 1).Resize(1, 1).Value
'Get the value of the third column
Val3 = SourceRange.Offset(ListBox1.ListIndex, 2).Resize(1, 1).Value
'Concatenate the three values together and display them in Label1
Label1.Caption = "Selected Data: " & vbNewLine & Val1 & " " & Val2 & " " & Val3
'Clean Up
Set SourceRange = Nothing
Dim newPage As Page
Dim PagesCnt As Long
With Me.MultiPage1
PagesCnt = .Count
Set newPage = .Pages.Add("Page" & (PagesCnt + 1), _
Val2 & (PagesCnt + 1), PagesCnt)
.Pages(PagesCnt).Controls.Copy
End With
End Sub
Private Sub MultiPage1_Change()
End Sub
Private Sub UserForm_Initialize()
With ListBox1
.Clear
.BoundColumn = 1
.ColumnCount = 4
.ColumnHeads = True
.RowSource = "Blad1!A2:B6"
End With
End Sub