VBA text to display hyperlink in Outlook email

Sven62

Active Member
Joined
Feb 21, 2012
Messages
485
My macro will create an email to defined addresses. I want the words "RESPONSE column" to be hyperlinked to the document address ..... etc etc . How do I do that? TIA!!!

Rich (BB code):
Set xOutApp = CreateObject("Outlook.Application")
        Set xMailItem = xOutApp.CreateItem(0)
        xMailBody = "The RESPONSE column of the Employee Onboarding worksheet was modified on " & _
            Format$(Now, "mm/dd/yyyy") & " at " & Format$(Now, "hh:mm:ss") & _
            " by " & Environ$("username") & "." & vbNewLine & vbNewLine & "You're up, slugger!"
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
This attempt failed due to Error (13) Type Mismatch

Rich (BB code):
xMailBody = "The RESPONSE column of the" & "<a href=" / "https://my.sharepoint.com/:x:/r/personal/_layouts/15/..."">Employee Onboarding worksheet</a> was modified on " & _
            Format$(Now, "mm/dd/yyyy") & " at " & Format$(Now, "hh:mm:ss") & _
            " by " & Environ$("username") & "." & vbNewLine & vbNewLine & "You're up, slugger!"
 
Upvote 0
something like:

Code:
Sub SendHyperEmail()
Dim vCode, vFld2, vFld5, vFld6
Dim vTo, vSubj, vBody
Dim iLastRow As Long
Const Q = """"

  'goto last row
Range("A1").Select
'Selection.End(xlDown).Select

vBody = "The RESPONSE column of the Employee Onboarding worksheet was modified on <br>"
vBody = vBody & "Date=" & Format(Date, "mm/dd/yyyy") & "<br><br>"
vBody = vBody & "<a href=" & Q & "https://my.sharepoint.com/?/r/personal/_layouts" & Q & ">RESPONSE column</a>"

vTo = "wile.E.coyote@acme.com"   'or range("A7").value
vSubj = "your data"

'send email
Send1Email vTo, vSubj, vBody
End Sub

'-------
'YOU MUST ADD THE OUTLOOK APP IN REFERENCES!!! checkmark OUTLOOK OBJECTS in the vbE menu, Tools, References
'-------
Public Function Send1Email(ByVal pvTo, ByVal pvSubj, ByVal pvBody, Optional pvFile) As Boolean
Dim oApp As Outlook.Application
Dim oMail As Outlook.MailItem
On Error GoTo ErrMail
Set oApp = GetApplication("Outlook.Application")
'Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(olMailItem)
With oMail
.To = pvTo
.Subject = pvSubj

.HTMLBody = pvBody
'.Body = pvBody
  
    If Not IsMissing(pvFile) Then .Attachments.Add pvFile, olByValue, 1

.Display True
'or
'.Send
End With
Send1Email = True
Set oMail = Nothing
Set oApp = Nothing
Exit Function
ErrMail:
MsgBox Err.Description, vbCritical, Err
'Resume Next
Set oApp = Nothing
End Function


Function GetApplication(className As String) As Object
' function to encapsulate the instantiation of an application object
Dim theApp As Object
On Error Resume Next
Set theApp = GetObject(, className)
If Err.Number <> 0 Then
'MsgBox "Unable to Get" & className & ", attempting to CreateObject"
Set theApp = CreateObject(className)
End If
If theApp Is Nothing Then
Err.Raise Err.Number, Err.Source, "Unable to Get or Create the " & className & "!"
Set GetApplication = Nothing
End If
'MsgBox "Successfully got a handle on Outlook Application, returning to caller"
Set GetApplication = theApp
End Function
 
Upvote 0
This is what a link looks like?
Code:
<a href="https://www.mrexcel.com/board/threads/vba-text-to-display-hyperlink-in-outlook-email.1157107/">Test Link</a>
 
Upvote 0
My macro will create an email to defined addresses. I want the words "RESPONSE column" to be hyperlinked to the document address https://my.sharepoint.com/❌/r/personal/_layouts
Like this, assigning the string to the HTMLBody property as shown, not the HTML property:
VBA Code:
    xMailBody = "<p>The <a href='http://www.yourlink.com/page.html'>RESPONSE column</a> of the Employee Onboarding worksheet was modified on " & _
                Format$(Now, "mm/dd/yyyy") & " at " & Format$(Now, "hh:mm:ss") & _
                " by " & Environ$("username") & ".</p><p>You're up, slugger!</p>"
    xMailItem.HTMLBody = xMailBody
 
Upvote 0
Like this, assigning the string to the HTMLBody property as shown, not the HTML property:
VBA Code:
    xMailBody = "<p>The <a href='http://www.yourlink.com/page.html'>RESPONSE column</a> of the Employee Onboarding worksheet was modified on " & _
                Format$(Now, "mm/dd/yyyy") & " at " & Format$(Now, "hh:mm:ss") & _
                " by " & Environ$("username") & ".</p><p>You're up, slugger!</p>"
    xMailItem.HTMLBody = xMailBody
Syntax Error
 
Upvote 0
I'm not onvinced you need the single quotes? You do not see any in my link?

Debug.Print xMailBody to see what it contains an modify until it works.
 
Upvote 0
This is what a link looks like?
Code:
<a href="https://www.mrexcel.com/board/threads/vba-text-to-display-hyperlink-in-outlook-email.1157107/">Test Link</a>
Yes but I get the Expected End Statement error
End Statement.PNG
 
Upvote 0
I'm not onvinced you need the single quotes? You do not see any in my link?

Debug.Print xMailBody to see what it contains an modify until it works.
I don't know what Debug.Print xMailBody means or how to implement that. Sorry. I wish I knew more!
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,376
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top