How to add a Hyperlink in an E-Mail based on Excel

AnnAbel97

New Member
Joined
Jul 29, 2021
Messages
5
Dear World,

my Name is Annabel and I am quite new at world of VBA. I must admit I absolutely adore the feeling, when something works. Maybe you can help me, to get this feeling back.

I just learned how to generate an E-Mail based on an Excel-table. Now I would like to add a LINK when clicking on a special word.

The actual code is as follows:


VBA Code:
Sub Bulkversand()


Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Bulkversand_JF_TP")


Dim OA As Object
Dim msg As Object


'Update Date in List


ThisWorkbook.Sheets("Bulkversand").Range("G2").Value = Date


'Create Mail based on List


Set OA = CreateObject("Outlook.Application")


Dim i As Integer
Dim last_row As Integer


last_row = Application.WorksheetFunction.CountA(sh.Range("A:A"))


For i = 2 To last_row


Set msg = OA.CreateItem(0)


msg.To = sh.Range("A" & i).Value
msg.CC = sh.Range("B" & i).Value
msg.Subject = sh.Range("C" & i).Value
msg.Body = sh.Range("D" & i).Value




If sh.Range("E" & i).Value <> "" Then
msg.Attachments.Add sh.Range("E" & i).Value


End If


msg.Display 'alternativ .send


Next i


End Sub
[/ICODE]

The basic table is like this:

ToCCSubjectBodyAttachments
XXX@x.comsomeone@y.comSomethingHi there,

please check out the following Link. (Here I would aprreciate a Link to Sharepoint when clicking on the word "Link")

BR
Annabel

Do you know how to edit the code?
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Is the link already part of the "Body" data or is that going to come from another cell in the worksheet?
 
Upvote 0
Hi Crystalyzer, thanks for your message! Until now I haven't decided, it didn't work. Maybe you have an idea?
 
Upvote 0
If you are able to change your worksheet format as below
Book3
ABCDEFGHI
1ToCCSubjectGreetingBodyLinkClosingSignatureAttachment
2xxx@x.comsomeone@Yahoo.comSomethingHi There,Please check out the followingDoodle Champion Island Games!Best Regards,Annabel
Bulkversand_JF_TP


Then this code should do the trick

VBA Code:
Sub Bulkversand()
    Dim sh As Worksheet
    Dim OA As Outlook.Application
    Dim msg As Outlook.MailItem
    Dim i As Integer
    Dim last_row As Integer
    
    Set sh = ThisWorkbook.Sheets("Bulkversand_JF_TP")
    Set OA = New Outlook.Application
    
    last_row = sh.Cells(Rows.Count, 1).End(xlUp).Row
    
    For i = 2 To last_row
        Set msg = OA.CreateItem(olMailItem)
        msg.To = sh.Range("A" & i).Value
        msg.CC = sh.Range("B" & i).Value
        msg.Subject = sh.Range("C" & i).Value
        msg.HTMLBody = sh.Range("D" & i).Value & "<br /><br />" & _
             sh.Range("E" & i).Value & " <a href='" & sh.Range("E" & i).Value & "'>LINK</a>." _
             & "<br /><br />" & sh.Range("G" & i).Value & "<br />" & sh.Range("H" & i).Value
        If sh.Range("I" & i).Value <> "" Then msg.Attachments.Add sh.Range("E" & i).Value
        msg.Display 'alternativ .send
    Next i
End Sub
 
Upvote 0
Solution
Hi Crystalyzer, do you maybe also know how to add a signature? I would love to put the signature thats popping up when opening a new mail under my text. I've tried various ways of the internet, but unfortunately they are not really working.. Can you help me?
 
Upvote 0
Does your signature already exist in outlook? If not, you would need to create it and provide me with the name of the file you want to use and the path of it's location.
 
Upvote 0
If I write a normal E-Mail there is a signature. But when I start my Mailing-Macro it's away and I have to add it manually. So you mean I have to export it in a PDF or which kind of data-format? Let's say the file was named "Signature" and was stored on my desktop. What would be the code?
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,731
Members
448,987
Latest member
marion_davis

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