Treygor
11-04-2006, 05:43 PM
I have dynamically created some listboxes with the following code and I want to know if it is possible to hyperlink the information that is displayed in the Listbox. I run into the problem where I do not know how to use, for example, the 3rd listbox that was dynamically created. When these items are drag and dropped into the userform, I understand that each listbox is an object but how do you refer to a dynamically created object?
I would like to allow the user to simply click on one particular listindex within any given listbox and then have the listindex open a file. Sorry if the code is confusing. Thanks in advance
-Treygor
Sub Set_Page_Topics()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''
'This code will find the number of files in a certain folder and all of its sub folders.
'File_Name(III) will hold the names of all of those files.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''
Set FS = Application.FileSearch
Dim File_Name(20) As String
With FS
.LookIn = "C:\Documents and Settings\"
.SearchSubFolders = True
.FileName = "*"
If .Execute() > 0 Then
MsgBox "There were " & .FoundFiles.Count & " file(s) found."
Number_Of_Files = .FoundFiles.Count
For III = 1 To Number_Of_Files
File_Name(III) = .FoundFiles(III)
Next III
Else
MsgBox "There were no files found."
End If
End With
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''
Dim i, II As Integer
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'allows me to name the dynamically created multipage and listbox
Dim NewMPage As MSForms.MultiPage
Dim NewLbox As MSForms.ListBox
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
i = 1
''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Initialize the multipage to have zero pages to start.
UserForm1.MultiPage1.Pages.Clear
''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
'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 = 700
Do While Sheet1.Cells(II, i) > "" 'Names each dynamically created multipage sheet
With NewMPage.Pages.Add
.Caption = Sheet1.Cells(II, i)
Set NewLbox = .Controls.Add("Forms.LIstbox.1") 'adds dynamic listbox to every nested multipage
NewLbox.Height = 200
NewLbox.Width = 600
NewLbox.Clear
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''
'The following code will place all of the file names paths that are contained with in a certain folder.
For III = 0 To Number_Of_Files
NewLbox.AddItem File_Name(III) '??? How do I enable each new item added to the list box to be hyperlinked to a file?
Next III
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''
End With
II = II + 1 'Counter
Loop
End With
i = i + 1 'Counter
Loop
End Sub
I would like to allow the user to simply click on one particular listindex within any given listbox and then have the listindex open a file. Sorry if the code is confusing. Thanks in advance
-Treygor
Sub Set_Page_Topics()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''
'This code will find the number of files in a certain folder and all of its sub folders.
'File_Name(III) will hold the names of all of those files.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''
Set FS = Application.FileSearch
Dim File_Name(20) As String
With FS
.LookIn = "C:\Documents and Settings\"
.SearchSubFolders = True
.FileName = "*"
If .Execute() > 0 Then
MsgBox "There were " & .FoundFiles.Count & " file(s) found."
Number_Of_Files = .FoundFiles.Count
For III = 1 To Number_Of_Files
File_Name(III) = .FoundFiles(III)
Next III
Else
MsgBox "There were no files found."
End If
End With
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''
Dim i, II As Integer
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'allows me to name the dynamically created multipage and listbox
Dim NewMPage As MSForms.MultiPage
Dim NewLbox As MSForms.ListBox
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
i = 1
''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Initialize the multipage to have zero pages to start.
UserForm1.MultiPage1.Pages.Clear
''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
'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 = 700
Do While Sheet1.Cells(II, i) > "" 'Names each dynamically created multipage sheet
With NewMPage.Pages.Add
.Caption = Sheet1.Cells(II, i)
Set NewLbox = .Controls.Add("Forms.LIstbox.1") 'adds dynamic listbox to every nested multipage
NewLbox.Height = 200
NewLbox.Width = 600
NewLbox.Clear
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''
'The following code will place all of the file names paths that are contained with in a certain folder.
For III = 0 To Number_Of_Files
NewLbox.AddItem File_Name(III) '??? How do I enable each new item added to the list box to be hyperlinked to a file?
Next III
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''
End With
II = II + 1 'Counter
Loop
End With
i = i + 1 'Counter
Loop
End Sub