Consulting

Results 1 to 7 of 7

Thread: Solved: Adding a hyperlink to email body

  1. #1
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location

    Solved: Adding a hyperlink to email body

    I'm saving attachments to a folder and want to add a hyperlink to the email which will then be saved in pdf format. This is my code to create the hyperlink (the Else option is used)

    [VBA]Function AddFileSave(strCopiedFiles As String, objMsg As Outlook.MailItem, strfile As String)
    'write the save as path to a string to add to the message
    'check for html and use html tags in link
    If objMsg.BodyFormat <> olFormatHTML Then
    AddFileSave = strCopiedFiles & vbCrLf & "<file://" & strfile & ">"
    Else
    AddFileSave = strCopiedFiles & "<br>" & "<a " & strfile & "'>" & strfile & "</a>"
    End If
    End Function
    [/VBA]

    and is written to the Body

    [VBA]If lngCount > 0 Then
    If objMsg.BodyFormat <> olFormatHTML Then
    objMsg.Body = objMsg.Body & vbCrLf & _
    "The file(s) were saved to " & strCopiedFiles
    Else
    objMsg.HTMLBody = objMsg.HTMLBody & "<p>" & _
    "The file(s) were saved to " & strCopiedFiles
    End If
    objMsg.Save
    End If[/VBA]
    to give this output, but no hyperlink. What am I missing?

    The file(s) were saved to
    M:\1628 SEPA Aberdeen Alterations\Attachments\080228 - 08-02-26 Sinclair Road Interim Certificate no 1-7.pdf
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  2. #2
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I see my pasted text has posted as a hyperlink. I don't follow this at all!!!
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Are you sure the HTML is correct?

    I see you are using the anchor tag a but you don't seem to be using href.

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Norie,
    Thanks for the response.
    If my HTML was correct, I guess I wouldn't have this problem. Should I be using "href"? How about posting an answer instead of vague statements. I clearly haven't used href. There is no "seems" about it.
    Regards
    MD
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    I tried this on one open mailmessage with the html format as mailformat.[vba]Sub save_attachment_current_mail()
    Dim myattach As Outlook.attachment
    Dim test_this
    For Each myattach In ActiveExplorer.Selection(1).Attachments
    test_this = AddFileSave("C:\Data\" & myattach.FileName, _
    ActiveExplorer.Selection(1), myattach.FileName)
    ActiveExplorer.Selection(1).Body = ActiveExplorer.Selection(1).Body & test_this
    Next myattach
    End Sub
    Function AddFileSave(strCopiedFiles As String, objMsg As Outlook.MailItem, strfile As String)
    'write the save as path to a string to add to the message
    'check for html and use html tags in link
    If objMsg.BodyFormat <> olFormatHTML Then
    AddFileSave = strCopiedFiles & vbCrLf & "<file://" & strfile & ">"
    Else
    'changed it to this when html format
    AddFileSave = "--> file://" & strCopiedFiles & ">"
    End If
    End Function[/vba]

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I finally achieved success with
    [vba]
    AddFileSave = "<br><a href=" & Chr(34) & "file://" & strfile & Chr(34) & ">" & strfile & "</a><br>"

    [/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Quote Originally Posted by mdmackillop
    How about posting an answer instead of vague statements.
    MD

    That's a bit harsh.

    I actually had to check it out myself on an HTML site if you needed it.

    Wasn't sure if it was required when linking to a file.

    Was going to post back but other things came up.

    Anyways, glad to see you've got it sorted.

Posting Permissions

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