Web browser open through ListBox control on Userform

sanits591

Active Member
Joined
May 30, 2010
Messages
253
Hi,

Given Data
I have an excel file having number of sheets with cells duly filled up with the hyperlink friendly name (not the url address or linked to various websites) are hyperlinked to different sites.

The cells which are filled up (having words) are searched through a Userform and the results of the search are displayed in a Listbox.

An excel sheet is attached Sample file.

Now my requirement is:

As soon as i click on the Listbox for the searched word, i want the webrowser control which is there on the Userform to display the webpage (i.e. take the web address through the searched cell.

I have tried the vba code in the file itself, but unable to get any results, please help me out on this.

Thanks!
 
Last edited:

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Where are these 'user-friendly' hyperlinks in the file?
 
Upvote 0
The user friendly link name is sheet 1 ("a7") = "Test", & sheet 2 ("a14") = "Test2".

Only 2 links have been given as an example for this.
 
Upvote 0
Declare a module level dynamic array and when you populate the listbox with the friendly names populate the array with the respective hyperlink addresses while respecting the indexes.

Then on the listbox click event run something along these lines :

Code:
Private Sub ListBox1_Click()

    WebBrowser1.Navigate YouArray(ListBox1.ListIndex)

End Sub
 
Upvote 0
Thanks for giving the directions, could you please elaborate a little further, as the hyperlinks have friendly names and are not to be populated in the listbox. There are 0.5 million of words in the sheet with these friendly names with hyperlinks.

Request to help me out on this.
 
Upvote 0
Why not just copy the hyperlinks?
Code:
  ws.Cells(varRow, 1).Copy wsTemp.Range("A" & LR).Offset(1, 0)
 
Upvote 0
Thanks Norie!, the suggestion to this is appreciated, but again that friendly name (hypelinked to some site) is to be taken to the web browser control for accessing the required website.
This is the one where this all is stuck up.
 
Upvote 0
Why can't you do that?

The hyperlink is in tmpSearch so there's nothing stopping you accessing it.

I added a command button and this code:
Code:
Private Sub CommandButton4_Click()
Dim I As Long
Dim strURL As String

    For I = 0 To lstResults.ListCount - 1
        If lstResults.Selected(I) Then
            strURL = Worksheets("tmpSearch").Range("A" & I + 2).Hyperlinks(1).Address
            WebBrowser1.Navigate strURL
        End If
    Next I
End Sub
When I searched for Test the items returned in the listbox were Test and Test2.

I selected Test2 and hit the new command button.

The webbrowser navigated to microsoft.com.
 
Last edited:
Upvote 0
I want this friendly name (having hyperlink) in the tempSearch sheet to be accessed through the ListBox on the Userform, by which clicking on the listbox value the Webbrowser control on the userform to open the website.

The hyperlink, i.e. URL address not to be shown in the Listbox control, only the friendly name is to be displayed in the Listbox control on the Userform.
 
Last edited:
Upvote 0
Same code but for the double click event of the listbox.
Code:
Private Sub lstResults_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim strURL As String
    If lstResults.ListIndex <> -1 Then

        strURL = Worksheets("tmpSearch").Range("A" & lstResults.ListIndex + 2).Hyperlinks(1).Address
        WebBrowser1.Navigate strURL
    End If

End Sub
This works for the 2 hyperlinks in the workbook, but you need to change the listbox to single select and copy as I suggested in post #6.
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,181
Members
452,893
Latest member
denay

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top