Open a URL in VB6

I was modifying a VB6 application to include a button that launches a browser to navigate to a URL. I wanted to use the default browser and open the link in an existing window, if one existed. This was accomplished easily with the ShellExecute API command.

First, you need your API function declaration in a code module:

Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
    (ByVal hwnd As Long, ByVal lpszOp As String, _
     ByVal lpszFile As String, ByVal lpszParams As String, _
     ByVal LpszDir As String, ByVal FsShowCmd As Long) _
    As Long

Then you can use the API to open your URL, like so:

ShellExecute 0, vbNullString, "http://adamprescott.net", vbNullString, vbNullString, vbNormalFocus

Author: Adam Prescott

I'm enthusiastic and passionate about creating intuitive, great-looking software. I strive to find the simplest solutions to complex problems, and I embrace agile principles and test-driven development.

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s