VBA - Outlook Email

30136353

Board Regular
Joined
Aug 14, 2019
Messages
105
Hi Guys,

I have the below code, working almost to how I need it. The 3 additional things I need ot get right, and I amstrugling with:

1 - The body text is in the wrong font / size, I need this configured to calibri(body) size 11, black font.
2 - My email signature does pastes in at the bottom as needed, but its in a different font/ colour as my original and loses the hyperlinks etc...
3 - Within the body to replace the middle blank line " " & vbNewLine & _ - I would like to paste in a range of cells A8:J39...

(Don't worry about the stars within the quotes, its to blank out sens info)

Any help would be appreciated.

VBA Code:
    Sub Send_Emails()

    Dim oLook As Object, oMail As Object, Signature As String
 

    Set oLook = CreateObject("Outlook.Application")
Set oMail = oLook.CreateItem(0)

With oMail
    .Display

    End With

    Signature = oMail.Body

     With oMail

     .To = "***;" & "***;"
.CC = "***;" & "***;"
.Subject = "*** - " & Range("c2").Value & " " & Range("I2").Value & " @ " & Range("K8").Value & " ***"
.Body = "Hi Guys," & vbNewLine & vbNewLine & _
"**** " & Range("K10").Value & " *** " & Range("c2").Value & " " & Range("I2").Value & " of " & Range("K4") & " *** " & Range("K8").Value & " SHP." & vbNewLine & _
" " & vbNewLine & _
"DL - Please find below *** " & Range("k12") & " ****" & vbNewLine & _
" " & vbNewLine & _
" " & vbNewLine & _
" " & vbNewLine & _
"Thanks." & Signature

    End With

    Set oMail = Nothing
    Set oLook = Nothing

    End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi,

Look at using .HTMLBody for the email instead of Text
Ron De Bruin has a function here called RangetoHTML that keeps the format of the range you are copying from Excel to the mail body.


You can modify it to keep hyperlinks:

Using HTML in the body requires that vbNewline be replaced with html break tags '<br>' and you treat it as a string e.g "<br><br>"
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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