VB Center | Code Library | Internet |
Open a URL into the Default Internet Browser
Written exclusively for VB Center by Marco Cordero.
Start a new project. To the form, add a label as described below.
Type | Name | Index | Caption |
Label | URL | http://www.microsoft.com |
Place the following in the general declarations area of the form.
#If Win32 Then
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
#Else
Private Declare Function ShellExecute Lib _
"shell.dll" _
(ByVal hwnd As Integer, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Integer) As Integer
#End If
Private Const SW_SHOWNORMAL = 1
Add the following code to the label.
Private Sub
URL_Click()
Dim iret As Long
' open URL
into the default internet browser
iret =
ShellExecute(Me.hwnd, vbNullString, _
"http://www.microsoft.com", vbNullString, _
"c:\", SW_SHOWNORMAL)
End Sub
Now, press F5 to run the project. If you click the label, it will open the URL "http://www.microsoft.com" into the default Internet browser.