PDA

View Full Version : Sleeper: Create a hyperlink in email text body



Thymen
02-27-2006, 08:07 AM
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 (http://www.thecodenet.com)





Help greatly appreciated!


Thymen

gibbo1715
02-27-2006, 08:13 AM
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

Norie
02-27-2006, 09:05 AM
Instead of Body try using HTMLBody.


aEmail.HTMLBody = "<a href=http://www.vbaexpress.com>VBA Express</a>"

Kidiot
01-19-2018, 04:21 AM
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?

Logit
01-19-2018, 10:05 AM
.
https://www.rondebruin.nl/win/s1/outlook/bmail10.htm

Looks like not enough quotation marks in the right locations.