PDA

View Full Version : view hyperlink on a userform



hamz
12-11-2006, 04:46 PM
Hi everyone!I am new with VBA, i have made a VB program in excel, a useform, 5 labels and a combobox. A user selects from the combobox and the informationof that particular selction appears on the labels. Now,the workbook source of my program has cells that has hyperlinks. The word can be viewed on the labels but it's not a hyperlink. I want that the hyperlink can be viewed on the userform's labels so that the user can click on it to access the linked file.Is it possible? Or there's an alternative way of achieving it with the same results?Thanks.

Bob Phillips
12-11-2006, 06:30 PM
I think that you need to get the address or the subaddress properties of the hyperlink object. Without seeing your code, I would struggle to be more precise.

malik641
12-11-2006, 07:00 PM
Hi hamz, welcome to VBAX :hi:

This is one way you could do it, just by using the click event of the Label object on your form. On the Initialize event (right before the form loads) I tooks cells from Sheet1 column A that only had hyperlinks and stored them into a 2-dimensional array (one slot for the cell text, and the other for the hyperlink address). Once you select an item from the combobox the label will show the text of the combobox. Once you select the label, the code will perform a search in the array for the text from the label. If there's a match, the code will use the ThisWorkbook.FollowHyperlink method to act as if you clicked a hyperlink. Please note that some users have experienced some kind of warning message when using the FollowHyperlink method, although I have not yet seen it.

Take a look at the example, hope this helps :)

hamz
12-11-2006, 07:04 PM
Hi! thanks for your reply, below are the codes i use in viewing the cell content in sheet2 to a label. It can be view on the label but just a plain text, not ashyperlink format. Private Sub UserForm_Initialize()
ComboBox1.RowSource = Sheet2.Range("E3", _
Sheet2.Range("E65536").End(xlUp)).Address
ComboBox1.ListIndex = 0
ComboBox1.SetFocus
End Sub

Private Sub ComboBox1_Change()
With Worksheets("Sheet2") Label1.Caption = .Range("D3").Offset(ComboBox1.ListIndex)
Label2.Caption = .Range("G3").Offset(ComboBox1.ListIndex)
Label3.Caption= .Range("C3").Offset(ComboBox1.ListIndex)
Label4.Caption = .Range("F3").Offset(ComboBox1.ListIndex)
End Sub

lucas
12-11-2006, 09:18 PM
Moved to the Excel help forum and merged with duplicate post. hamz, you will find more help in this area for your question.