VBA send email OutMail .Body question

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
1,124
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I'm using this code that I've come up with on a previous post and it works really very nicely.


https://www.mrexcel.com/forum/excel-questions/1037579-vba-send-email-attachment-question.html


If you take a look at the code, I have the OutMail referencing a cell to gain the information that I need to post inside the email.

So, My question is, 'How do I change the OutMail font?

For example, Can I reference a word document as to be used as template for my OutMail message??


Code:
Option Explicit
Sub sendemail()

    Dim FileExtStr As String:confused:
    Dim FileFormatNum As Long
    Dim Sourcewb As Workbook
    Dim Destwb As Workbook
    Dim TempFilePath As String
    Dim TempFileName As String
    Dim OutApp As Object
    Dim OutMail As Object
    Dim varMyAttachment As Variant
  
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
        
    With OutMail
        .To = Worksheets("admin").Range("f9").Value
        .CC = Worksheets("admin").Range("f10").Value
        .BCC = ""
        .Subject = Worksheets("admin").Range("i11").Value
        .Body = Worksheets("admin").Range("[B]i[B]12[/B]"[/B]).Value
        'For a single file:
        .Attachments.Add ("C:\File1.xlsb")
        'For multiple files:
        For Each varMyAttachment In Array("C:\File1.xlsb", "C:\File2.xlsb")
            .Attachments.Add varMyAttachment
        Next varMyAttachment
        .Display
    End With
    
End Sub


Please let me know, what are your thoughts hopefully expressed in code.

Thank you!
Pinaceous
 
Last edited:

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
I think you'll need to use the HTMLBody property. For example, to set the font to Verdana and the size at 100%, try (note that I've added a space after each occurrence of '<' to prevent the Board from interpreting it as HTML code, so you'll need to remove those spaces)...

Code:
.HTMLBody = "< body style=""font-family:verdana; font-size:100%;"">" & [COLOR=#574123]Worksheets("admin").Range("[/COLOR][B]i[B]12[/B]"[/B][COLOR=#574123]).Value[/COLOR] & "< /body>"

If you want to use a template instead, first create one and save the .oft file in a folder. Then replace...

Code:
[COLOR=#574123]Set OutMail = OutApp.CreateItem(0)[/COLOR]

with

Code:
Set [COLOR=#574123]OutMail[/COLOR] = [COLOR=#574123]OutApp[/COLOR].CreateItemFromTemplate("C:\Users\Domenic\Documents\MyTemplate.oft")

Hope this helps!
 
Upvote 0
Hi Domenic,

I'm sorry for the delay, I was still trying to work out the criteria on my end. I've tested out the update that you suggested and it looks really great!

Many thanks again!

Paul
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,179
Members
453,021
Latest member
Justyna P

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