VBA OutMail Help: Body of Text from Word Document

S_W_Langdon

New Member
Joined
Feb 5, 2018
Messages
13
Hello Everyone,

I am hoping someone can help,
I have setup some VBA to send out Documents via a list of people and addresses within my Excel List, this works fine for most areas, but I have one area that needs a custom Body of text per email and I am unsure on how to do this.

Here is my code so far, as you can see the the To: goes to every email within my list but the Subject/ Body are static based on cells.

Code:
Sub Send_Files()    Dim OutApp As Object
    Dim OutMail As Object
    Dim sh As Worksheet
    Dim cell As Range
    Dim FileCell As Range
    Dim rng As Range


    With Application
        .EnableEvents = False
        .ScreenUpdating = False
    End With


    Set sh = Sheets("Distribution")


    Set OutApp = CreateObject("Outlook.Application")


    For Each cell In sh.Columns("B").Cells.SpecialCells(xlCellTypeConstants)


               Set rng = sh.Cells(cell.Row, 1).Range("C1:d1")


        If cell.Value Like "?*@?*.?*" And _
           Application.WorksheetFunction.CountA(rng) > 0 Then
            Set OutMail = OutApp.CreateItem(0)


            With OutMail
[COLOR=#008000][B]                .To = cell.Value[/B][/COLOR]
[COLOR=#008000][B]                .Subject = Sheets("E-Mail Text").Range("B3").Value[/B][/COLOR]
[COLOR=#008000][B]                .Body = Sheets("E-Mail Text").Range("B6 & B6").Value[/B][/COLOR]


                For Each FileCell In rng.SpecialCells(xlCellTypeConstants)
                    If Trim(FileCell) <> "" Then
                        If Dir(FileCell.Value) <> "" Then
                            .Attachments.Add FileCell.Value
                        End If
                    End If
                Next FileCell


                .Send
            End With


       
            Set OutMail = Nothing
        End If
    Next cell


    Set OutApp = Nothing
    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With
        'Message box
   MsgBox "Finished"
    
End Sub

My initial thought is to pull information from Word Documents that are currently being used by this team to generate the email text, but I don't know where to start.

My second idea was to still use static fields, but to add in some fomula/ VBA that change parts of the text based on a loop within the VBA using the Email as a lookup value, but again this is beyond my current knowledge.

Any help would be great thanks everyone
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,214,649
Messages
6,120,728
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