Hyperlink in text (or anywhere). Use a LinkLabel >>

I have created a program that I plan on disbursing to other people, on this program, I have added a simple form with support info. I would like the text to be a hyperlink for a website and email.

Any suggestions

thanks




Answer this question

Hyperlink in text (or anywhere). Use a LinkLabel >>

  • Vegar Imsland

     

    Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, _

    ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) _

    Handles LinkLabel1.LinkClicked

     

    The above is all one line of code as in>>

    Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked

     I had split it using the line continuation technique as in>>

     If this were a line of code _

    it would be all one line

     You type a space character and a single underline >> _  << to break a line

    into separate physical lines. This can only be done at certain points in a line like after keywords, so as to avoid the "squigglies" >> squiggly lines when you get errors in a line of code.

    The lines are seen as one line of code by the system though.

    It would be easier if you just highlight, COPY and PASTE my code pasting.

     

    Regards,

    S_DS

     



  • Kishaloy

    Yes, this is VBA.

    that system process would not work either, I tried it as a button, a textbox, and as an event handler on an image.

    no luck.



  • Plum117

    Okay, stupid me, I did find where to put the web site, bt the system does not recognize the code in the () at the beginning - the part about ByVal and As.



  • Yngwie

    Okay, I still cannot get it to work below is my code for the entire page.

    Some of it is what you gave me earlier.

  • The Admiral

    Hi guys,

    VBA is not the same and VB.NET. The System.Diagnostic.Process object isn't in VBA and unfortunately neither is the link label control.

    If you want to have a link in a form in one of the Office applications then you need to fool the user by having a normal label control with blue underlined text that when clicked opens the site.

    You can use the shell command to open your web site. You but this in the label OnClick event.

    Shell "explorer http://www.yahoo.com", vbNormalFocus

    Unfortunately the hand mouse cursor isn't built into Excel so when the user moves the cursor over the link you might need to program the cursor change yourself using a cursor stored on file.



  • sugrhigh

    What sort of code would I use for changing the curser, I am guessing it would be in the mouseover event handler, but how do I do that

  • John CHLee

    So in that case would:

    Shell "explorer mailto:john@yahoo.com", vbNormalFocus

    be a valid line for it to automatically open an email similar to writing html

    Thank you soooo much for finally giving me something that works.



  • Can-Ann

    no worries, yeah shell mailto works, it's spawns an instance of the browser though but there's an other option for email, and for web pages as well...I'm going with Excel Useforms here. Try a search for hyperlink in the help if your using something else.

    ActiveWorkbook.FollowHyperlink "mailto:john@yahoo.com"

    For emails this won't spawn an instance of the browser.

    With the cursor at first I thought you'd might need to program it but there are properties of the label you can use to set the cursor at design time. Set the mousecursor to custom and specify a mouse icon. There are some here C:\WINDOWS\Cursors.

     



  • Chidu

    Stupid Question - Where does the web address go in this code

  • HSBF Lewe

     

    Hi,

    Sorry i've just spotted you said VBA.

    Could below is VB.Net, you might be able to convert it though.

    ===============================================

    Yes use a linkLabel as follows>>

    '-------------------------START OF CODE-----------------------------------------

    Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, _

    ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) _

    Handles LinkLabel1.LinkClicked

    Try

    VisitLink()

    Catch ex As Exception

    ' The error message

    MessageBox.Show("Unable to open link that was clicked.")

    End Try

    End Sub

    Private Sub VisitLink()

    ' Change the colour of the link text by setting LinkVisited

    ' to True.

    LinkLabel1.LinkVisited = True

    ' Call the Process.Start method to open the default browser

    ' with a URL:

    System.Diagnostics.Process.Start("http://www.w3schools.com/css/css_colornames.asp")

    End Sub

    '-------------------------END OF CODE-----------------------------------------

     

    Regards,

    S_DS

     



  • warble

     

    Hi,

    Are you are talking of VBA

    Try putting the line>>

    System.Diagnostics.Process.Start ("http://www.epc16.com")

    in the click event of a button instead and name it>>

     "Visit website." or something.

     

    Regards,

    S_DS

     



  • Hyperlink in text (or anywhere). Use a LinkLabel >>