Listbox with web links

ecoplan

New Member
Joined
Jun 26, 2012
Messages
11
Hello everyone,
I'm trying to figure out how to be able to list web pages name from a worksheet into a listbox and then when clicking on that link and click the "Consult" button, the selected web page should open. I already have that code:

Code:
Private Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" (ByVal hWnd As Long, _
ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long

Private Sub CommandButton5_Click()
Dim URL As String
    Dim Result As Long
    With Me.list_links
        If .ListIndex <> -1 Then
            URL = .Value
            Result = ShellExecute(0&, vbNullString, URL, _
            vbNullString, vbNullString, vbNormalFocus)
            If Result < 32 Then MsgBox "Error", vbCritical
        Else
            MsgBox "Please make a selection and try again!", vbExclamation
        End If
    End With
End Sub

Private Sub UserForm_Initialize()
Dim cLinks As Range
Set ws = Worksheets("Links")
For Each cLinks In ws.Range("Links_title")
  With Me.list_links
    .AddItem cLinks.Value
  End With
Next cLinks
End Sub

But I'm getting the ":oops: Error" msgBox every links I try EXCEPT for the http://www.microsoft.com that opens "C:\WINNT\system32\Microsoft" :confused:

Here's the link to my dummy worksheet: https://www.dropbox.com/s/yb12bjpdw8u8j0b/links_workbook.xls

Thanks!
 
Last edited:

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
You aren't listing the links in the listbox, all you have are the Page Titles, which aren't valid URLS.

To get the URL that corresponds to the selected title you can use this.
Code:
           URL = Worksheets("Links").Range("Links_Title")(.ListIndex + 1).Offset(, 1)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,219,162
Messages
6,146,660
Members
450,706
Latest member
LGVBPP

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