adding a hyperlink to an email body in vba

sdoppke

Well-known Member
Joined
Jun 10, 2010
Messages
647
Hi everyone, I am using the following script to send an email (works good) but want to add a hyperlink to the email. Id prefer if possible to show text as the hyper link. i.e. "Link" (not showing the path)

Thanks in advacne for any direction or help :)

sd

Code:
Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String
    Dim strUserName As String
    strUserName = Sheets("RDashboard").Range("AL1")
    Set rngSearch = Sheets("Pass").Range("A:A")
    Set rowFound = rngSearch.Find(What:=strUserName, LookIn:=xlValues, LookAt:=xlWhole)
    UserNames = Sheets("Pass").Range("C" & rowFound.Row)
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    strbody = "Hello" & vbNewLine & vbNewLine & _
              "This is an automated response to inform the next lever user  " & strUserName & " has been posted." & vbNewLine & vbNewLine & _
              "NEXT LEVEL USERS CLICK ON THE FOLLOWING LINK TO OPEN THE LAW WORKBOOK" & _
  ****IM ASSUMING THE LINK SYNTAX GOES HERE****
              "Thank you" & vbNewLine & _

    On Error Resume Next
    With OutMail
        .To = UserNames
        .CC = ""
        .BCC = ""
        .Subject = strUserName & " has posted"
        .Body = strbody
        'You can add a file like this
        '.Attachments.Add ("C:\test.txt")
        .Display   'or use .Display or use .Send
    End With
    
    On Error GoTo 0
    
    Set OutMail = Nothing
    Set OutApp = Nothing
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.


That absolutely helped! Here is what i came up with (a portion) but am having issues with the part in red. I will not include itselft in the link. Any ideas?

Code:
ThisLAW = ActiveSheet.Range("B4")
strbody = " < HTML > < BODY > "
strbody = strbody & " < A href=http://abcfedfghi.com/sites/Documents/ & ThisLAW & .xlsm > URL Text < /A > "
strbody = strbody & " < /BODY > < /HTML > "CODE]
 
Thanks a ton for the direction.
 
sd
 
Upvote 0
That absolutely helped! Here is what i came up with (a portion) but am having issues with the part in red. I will not include itselft in the link. Any ideas?

Code:
ThisLAW = ActiveSheet.Range("B4")
strbody = " < HTML > < BODY > "
strbody = strbody & " < A href=http://abcfedfghi.com/sites/Documents/ & [COLOR=red]ThisLAW[/COLOR] & .xlsm > URL Text < /A > "
strbody = strbody & " < /BODY > < /HTML > "CODE]
 
Thanks a ton for the direction.
 
sd[/QUOTE]
 
 
Sorry I realized there is no RED :(  Im having trouble with the ThisLAW portion.
 
Thanks for helping.
 
sd
 
Upvote 0
From what I can see you need quotation marks to stop/start within your concatenated string.

Try like:

strbody = strbody & " < A href=http://abcfedfghi.com/sites/Documents/" & ThisLAW & ".xlsm > URL Text < /A > "
____________________________________________________________^ __________^
 
Upvote 0
Also, remove all the spaces from within the quotation marks.
The only space your should have is:
A_href
 
Upvote 0
Could you please help me on the same with email Address on email body.
i've tried the below but its not working.

" < A href=""name.name@abc.com > name < /A > "

I just want to display only the alerts in email body with hyperlink.

Please help
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,588
Members
449,089
Latest member
Motoracer88

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