PDA

View Full Version : Solved: Adding a hyperlink to email body



mdmackillop
03-26-2008, 11:24 AM
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)

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


and is written to the Body

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
to give this output, but no hyperlink. What am I missing? :banghead:

The file(s) were saved to
M:\1628 SEPA Aberdeen Alterations\Attachments\080228 - 08-02-26 Sinclair Road Interim Certificate no 1-7.pdf (http://vbaexpress.com/forum/)

mdmackillop
03-26-2008, 11:27 AM
I see my pasted text has posted as a hyperlink. I don't follow this at all!!!

Norie
03-26-2008, 01:24 PM
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.

mdmackillop
03-26-2008, 04:07 PM
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

Charlize
03-27-2008, 01:01 AM
I tried this on one open mailmessage with the html format as mailformat.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

mdmackillop
03-27-2008, 10:32 AM
I finally achieved success with

AddFileSave = "<br><a href=" & Chr(34) & "file://" & strfile & Chr(34) & ">" & strfile & "</a><br>"

Norie
03-27-2008, 10:49 AM
How about posting an answer instead of vague statements.

MD

That's a bit harsh.:dunno

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.:)