Link to home
Start Free TrialLog in
Avatar of bgdw
bgdw

asked on

Hyperlink to a website

I have a VB application.  I have a help/about button that when pressed fires off a form.  The form contains information about the application: version, date, regsitration etc.  I would like to add a commandbutton to the "about" form that would, when pressed, link to a web page (hypelink).  

How do I create the hyperlink using a commandButton?
Avatar of blkbam
blkbam

Can't go wrong when someone has done it for you.

http://www.developerfusion.com/show/340/3/

Just be sure to give the author proper credit  :)
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
               
Private Const SW_SHOW = 1

'' then in onclick event of button

Private Sub Command1_Click()
  Dim href as String
  href = "http://www.google.com"
  hBrowse = ShellExecute(Me.hwnd, "open", href, vbnullstring, vbnullstring, SW_SHOW)
End Sub



But if you really want code:

Add a reference to "Microsoft Internet Controls"
then use the following code:

Public Sub LaunchSite(url As String)
    Dim ie As InternetExplorer
     Set ie = New InternetExplorer
    'open file in internet explorer
    With ie
        .Navigate2 url
        .Height = 800
        .Width = 700
        .Left = 25
        .Top = 25
        .Visible = True
    End With
    Set ie = Nothing
End Sub

url can be either a path and/or file name or an actual URL.
This article shows exactly what you want without use of any 3rd-party control, with the same look as an IE link... see which suits you better.

http://www.mvps.org/vbnet/code/intrinsic/sehyperlink.htm
'Put this in a module:
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

' And here is your code
Private Sub Command1_Click()
     Dim retval As Long
     retval = ShellExecute(hwnd, "Open", "http://www.google.com", "", App.Path, 1)
End Sub


Thanks & Cheers
private sub command1_click()
    Shell ("explorer http://www.google.com")
End Sub
ASKER CERTIFIED SOLUTION
Avatar of bobbit31
bobbit31
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Suggestion of bobbit31 will work out perfectly
Avatar of bgdw

ASKER

Thanks for the help.