Solved

create a hyperlink in vb6

Posted on 2004-08-31
5
1,141 Views
Last Modified: 2012-06-27
how can i create a hyperlink in vb6?

such as a button that will send an email to a set email address

thanks
0
Comment
Question by:rinkydink
5 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 11949171
Option Explicit

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_SHOWNORMAL = 1

Private Sub Command1_Click()
    ShellExecute Me.hwnd, vbNullString, "mailto:someOne@someIsp.net", _
        vbNullString, "C:\", SW_SHOWNORMAL
End Sub
0
 
LVL 19

Expert Comment

by:arif_eqbal
ID: 11949660
You can use ShellExecute to create a hyperlink, for eg. write the URL on a label and underline it to depict a hyperlink on the Click event of the Label use

Call ShellExecute( Me.hwnd, vbNullString, "http://google.com", vbNullString, "C:\", 1)

You need to declare the ShellExecute API at module/form level

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

if you give mailto:xxx in the URL it will open the default mail client for composing the mail and the user will have to send it.

0
 
LVL 2

Accepted Solution

by:
craigewens earned 100 total points
ID: 11950170
Create a label, and name it lblURL, and set its caption property to the internet address you want. If the URL is an email address, then un-comment one of the 'Call ShellExecute' lines, and comment out the line below that.

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 Sub lblURL_DragDrop(Source As Control, X As Single, Y As Single)
    If Source Is lblUrl Then
        With lblUrl
            .Font.Underline = False
            .ForeColor = vbBlack
            ' Call ShellExecute(0&, vbNullString, "Mailto:" & .Caption, vbNullString, vbNullString, vbNormalFocus)
            Call ShellExecute(0&, vbNullString, .Caption, vbNullString, vbNullString, vbNormalFocus)
        End With
    End If
End Sub

Private Sub lblURL_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
    If State = vbLeave Then
        With lblUrl
            .Drag vbEndDrag
            .Font.Underline = False
            .ForeColor = vbBlack
        End With
    End If
End Sub

Private Sub lblURL_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    With lblUrl
        .ForeColor = vbBlue
        .Font.Underline = True
        .Drag vbBeginDrag
    End With
End Sub
0
 
LVL 76

Expert Comment

by:David Lee
ID: 11950637
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question