Consulting

Results 1 to 5 of 5

Thread: Sleeper: Create a hyperlink in email text body

  1. #1
    VBAX Regular
    Joined
    Jan 2006
    Posts
    30
    Location

    Sleeper: Create a hyperlink in email text body

    Hi folks,

    plse have a look at the code below. I want to use it to send emails notifications from VBA Excel. I would like to include a hyperlink to the body (or even subject) of the email. How to do this? Add something like [/url:mysite.nl/url] in the body text?

    Private Sub CommandButton1_Click()
    Dim myRecipient As String Dim mySubject As String Dim myBody As String Dim myAttachments As String myRecipient = "myfriends@vbaforum.com" mySubject = "Please help me out..." myBody = "Now, I would like a Hyperlink here!" myAttachments = "" SendEmail myRecipient, mySubject, myBody, myAttachments End Sub Private Sub SendEmail(ByVal Recipient As String, ByVal Subject As String, _ ByVal Body As String, Optional ByVal Attachments As String) Dim aOutlook As Object Dim aEmail As Object On Error Resume Next Set aOutlook = GetObject(, "Outlook.Application") On Error Goto lNoOutlook If aOutlook Is Nothing Then Set aOutlook = CreateObject("Outlook.Application") Set aEmail = aOutlook.CreateItem(olmailitem) On Error Goto 0 aEmail.Subject = Subject aEmail.Body = Body If Not (Attachments = "") Then aEmail.Attachments.Add Attachments On Error Goto lNoSend aEmail.Recipients.Add Recipient aEmail.display 'or
    'aEmail.Send 'MsgBox "Email successfully sent."
    Exit Sub lNoSend: MsgBox "Email not sent.": Exit Sub lNoOutlook: MsgBox "Microsoft Outlook is not installed." End Sub
    VBA tags courtesy of www.thecodenet.com



    Help greatly appreciated!

    Thymen
    Last edited by Thymen; 02-27-2006 at 10:22 AM.

  2. #2
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    if your asking how to add a hyperlink to a file on your network within your email to another user on your network you would need to add something like

    "Click Here <File:\X:\Gibbo1715>"

    or "<file:\" & StrFile & ">" 'If using a string to hold your file path

    Or for a link to a webpage use

    <http://vbaexpress.com/forum/forumdisplay.php?f=17>

    Gibbo

  3. #3
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Instead of Body try using HTMLBody.
    aEmail.HTMLBody = "<a href=http://www.vbaexpress.com>VBA Express</a>"

  4. #4
    VBAX Newbie
    Joined
    Jan 2018
    Posts
    1
    Location
    Hello everybody.

    I've got the following code, but i can't get my link to work.




    ActiveWorkbook.SendMail _
        Recipients:=Range("B126"), _
        Subject:=Format(Date, "yyyy/mm/dd") & " Assortimentsaanvraag " & Range("I4")
    Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    strbody = "Goedendag," & vbNewLine & vbNewLine & _
              "Uw aanvraag is goedgekeurd door alle partijen en ingediend bij Artikelbeheer." & vbNewLine & _
              "" & vbNewLine & _
              "<A href="K:\Gedeelde Mappen\Assortimentsbeheer\Assortimentsaanvraag (Fmar100)\2018\" & Format(Date, "yyyy/mm/dd") & " Assortimentsaanvraag " & Range("I4") & ".xlsm" > Formulier </A>" & vbNewLine & ""
    On Error Resume Next
    With OutMail
        .To = Range("B126")
        .CC = ""
        .BCC = ""
        .Subject = Format(Date, "yyyy/mm/dd") & " Assortimentsaanvraag " & Range("I4")
        .Body = strbody
        .Send
    End With
    On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing






    Can anyone help me?
    Last edited by Kidiot; 01-19-2018 at 04:25 AM. Reason: Had to clearify

  5. #5
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    613
    Location
    .
    https://www.rondebruin.nl/win/s1/outlook/bmail10.htm

    Looks like not enough quotation marks in the right locations.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •