View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_5_] Dave Peterson[_5_] is offline
external usenet poster
 
Posts: 1,758
Default hyperlink in listbox

Maybe this will get you further along.

I put a listbox and two commandbuttons on a userform.

This is the code I used under the userform:

Option Explicit
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub CommandButton2_Click()
Dim myURL As String

If Me.ListBox1.ListIndex -1 Then
'something's selected
myURL = Me.ListBox1.List(Me.ListBox1.ListIndex, 1)
End If

If myURL = "" Then
'do nothing
Else
ThisWorkbook.FollowHyperlink Address:=myURL
End If

End Sub

Private Sub UserForm_Initialize()
Dim myCell As Range
Dim myRng As Range

With Me.ListBox1
.ColumnCount = 2
.ColumnWidths = "20;0"
.RowSource = ""
.Clear

With Worksheets("sheet1")
Set myRng = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp))
End With

For Each myCell In myRng.Cells
.AddItem myCell.Value
If myCell.Hyperlinks.Count 0 Then
.List(.ListCount - 1, 1) = myCell.Hyperlinks(1).Address
Else
.List(.ListCount - 1, 1) = ""
End If
Next myCell

End With

Unload Me

End Sub


Alen32 wrote:

I did try but doesn't work


--

Dave Peterson