Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A button in VB that opens webpage

Status
Not open for further replies.

vsprogrammer

Programmer
Jun 26, 2006
40
CA
Happy New Year to all!

I have a button in VB that when clicked on has to open a web page. Does anyone know of a quick way of doing this?

Thanks in advance!
 
I use the ShellExecute API to do this.

On a form, put this declaration at the top (just below Option Explicit).

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

Then, your click event for the button would be...

Code:
Private Sub Command1_Click()

    Call ShellExecute(0, "open", "[URL unfurl="true"]http://www.tek-tips.com",[/URL] vbNullString, vbNullString, 0)
    
End Sub

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
If you want it to open within your program add a WebBrowser control to your form and use the Navigate method in the buttons click event

If you want to open the default browser then shell to RUNDLL32. I use a standard function for opening ANY type of external file with its default application. In a module:
Code:
Public Function OpenDocument(DocumentWithPath As String) As Long
    OpenDocument = Shell("RUNDLL32.EXE URL.DLL,FileProtocolHandler " & DocumentWithPath, vbNormalFocus)
End Function

Then on your click event
Code:
x=OpenDocument("www.essexsteam.co.uk")

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
Thanks! This is what I was thinking but was not too sure. Will give it a try. Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top