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
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