Mini Browser - VBA (need opinion)

privxls

Board Regular
Joined
Nov 22, 2016
Messages
55
Office Version
  1. 2021
Platform
  1. Windows
Hi MrExcel,

I am currently working on a mini-experiment which is like an internet browser. I have a list of websites which are on a ListBox, every time a specific website is listed, the WebBrowser will navigate to the corresponding website which is selected from the ListBox.

I would like to ask about your opinion if there could be a better way to 'code' the following.
gzflCTR.png


And here is how it would somehow look like:
7FhfnNw.png


Kind regards,
~Privxls
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
I will try to use SELECT CASE and I will get back at you. I'll figure out how it works first, thank you Logit.
 
Upvote 0
.
You could use a SELECT CASE

Hi Logit, first off I would like to thank you. I was able to work with SELECT CASE and it's fantastic. It somehow made the 'code' less messy.

Here is a screenshot of it :)

CeTc79t.jpg


I am eager to learn more about Excel and VBA, it is fun and it will come in really handy.
Hope all is well for you, thank you so much again :)
 
Upvote 0
Another alternative to the original code would be to make the listbox multicolumn and put the URLs in a 2nd hidden column.

Then you could use something like this.
Code:
Private Sub CommandButton1_Click()
Dim idx As Long

    idx = ListBox1.ListIndex

    If idx = -1 Then
        MsgBox "No site selected."
        Exit Sub
    Else
        strURL = ListBox1.List(idx, 1)
        WebBrowser1.Navigate2 strURL
    End If

End Sub
 
Upvote 0
.
privxls

You are welcome. I too enjoy messing with Excel / VBA. It's a hobby for me. I especially enjoy helping others with my limited knowledge - as I best am able.
Helping others oftentimes increases my own knowledge level as I learn something new each time.

All the best.
 
Upvote 0
Another alternative to the original code would be to make the listbox multicolumn and put the URLs in a 2nd hidden column.

Then you could use something like this.
Code:
Private Sub CommandButton1_Click()
Dim idx As Long

    idx = ListBox1.ListIndex

    If idx = -1 Then
        MsgBox "No site selected."
        Exit Sub
    Else
        strURL = ListBox1.List(idx, 1)
        WebBrowser1.Navigate2 strURL
    End If

End Sub

Thank you so much, I will be trying this out on another project. I do appreciate the lively community :)
 
Upvote 0

Forum statistics

Threads
1,215,281
Messages
6,124,045
Members
449,139
Latest member
sramesh1024

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