Web browser control VBA (Visual Basic for Applications) example

Web browser control VBA (Visual Basic for Applications) example

WebBrowser

Is an inbuilt control comes along with default Office environment. In this PoC we will create a sample project which will use a listbox having list of web address. Upon double click each url will navigate into Web browser.

Step 1: Create a user form and place one listbox and Web Browser as shown below:

To get the Web browser control in toolbox follow below steps:

  1. Right click on toolbox
  2. Select additional control (refer below screenshot 1.1)
  3. Select Microsoft Web Browser control from the list of controls (refer below screenshot 1.2)
  4. Check and OK
  5. The control will be available on toolbox as shown below (refer screenshot 1.3) which you can drag over the form and drop.
1.1
1.2
1.3

Step 2: put code behind form as shown below:

Code UserForm Initialize

Private Sub UserForm_Initialize()
    ListBox1.AddItem "https://www.vbaoverall.com"
    ListBox1.AddItem "https://www.infoextract.in"
End Sub

Listbox double click

Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
WebBrowser1.Navigate ListBox1.Text
End Sub

Button Unload form

Private Sub CommandButton1_Click()
Unload Me
End Sub

Overall code

Step 3: Run code and it appears as below:

Step 4: double click on any item and it will load url as shown below:

Next >> String to number conversion using VBA example

Leave a Reply

Your email address will not be published.