I have multiple labels created dynamically on Userform. I want to add a hyperlink to the created labels, is there a way I could add hyperlink to these labels. Here is the code of how I created the labels dynamically.
Private Sub cmdViewReports_Click()
Dim row_num As Long
Dim fso As Object
Dim src_path As String
Dim dest_path As String
Dim sub_folder As String
Dim theLabel1 As msforms.Label
Dim inc As Integer
Dim my_files As Object
Dim my_folder As Object
Dim i As Integer
Dim ctrl As Control
'Check if the record is selected in listbox
If Selected_List = 0 Then
MsgBox "No record is selected.", vbOKOnly + vbInformation, "Upload Results"
Exit Sub
End If
'Folder Name to be created as per the 3rd column value in the list
sub_folder = Me.lstDb.List(Me.lstDb.ListIndex, 3)
sub_folder = Replace(sub_folder, "/", "_")
dest_path = "C:\abc\xyz\Desktop\FV\" & sub_folder & "\"
Set fso = CreateObject("scripting.filesystemobject")
If Not fso.FolderExists(dest_path) Then
MsgBox "No reports are loaded"
Exit Sub
End If
Set my_folder = fso.GetFolder(dest_path)
Set my_files = my_folder.Files
i = 1
For Each oFiles In my_files
Set theLabel1 = Me.Frame1.Controls.Add("Forms.Label.1", "File_name" & i, True)
With theLabel1
.Caption = oFiles.Name
.Left = 1038
.Width = 60
.Height = 12
.Top = 324 + inc
.TextAlign = 1
.BackColor = &HC0FFFF
.BackStyle = 0
.BorderStyle = 1
.BorderStyle = 0
'.Locked = True
.ForeColor = &H8000000D
.Font.Size = 9
.Font.Underline = True
.Visible = True
End With
inc = inc + 12
i = i + 1
Next
End Sub
here's how the part of the form looks like
To give a brief of my use case: I have some files/reports (pdf,word etc..) that I need to attach to a record. User can attach their reports to the records and also view reports if they are attached. So with the above code I am able to generate the labels with the files inside the folder; now when the file names are displayed on the form, I want a functionality where is I click the report(label) I want that report to open.
Thanks in Advance !!!