Macro to email to a list of people and include my company logo etc

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,210
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

Ok so I need a macro that can email Via Outlook,

The way I picture it is like this,

Column D from row 2 down holds a list of email Address,

Cell G10 Holds the Subject line

Cell G12 hold the Body of text

Cell G14 holds the link to any attachment

What I need is a macro that can email out one at a time using outlook to each email in Column D

now I have a company logo and my signature stored in outlook so if this could be included as well then great,

Thanks

Tony
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
'NOTE : YOU MUST HAVE THE OUTLOOK X.x Object Library REFERENCE CHECKED IN VBE; ctl-G, menu,tools, references, Microsoft Outlook XX Object library

paste code into excel module, then
open outlook,
run: SendAllEmails

Code:
Option Explicit
Public gvFile
Public gcolEmails As New Collection
Public Const kFILE = "c:\temp\File2mail.xls"

Public Function Send1Email(ByVal pvTo, ByVal pvSubj, ByVal pvBody, Optional ByVal pvFile) As Boolean
Dim oMail As Outlook.MailItem
Dim oApp As Outlook.Application
Dim vPage
On Error GoTo ErrMail
'NOTE : YOU MUST HAVE THE OUTLOOK X.x Object Library    REFERENCE CHECKED IN VBE; ctl-G, menu,tools, references, Microsoft Outlook XX Object library
Set oApp = GetApplication("Outlook.Application")  'it may be open already so use this
'Set oApp = CreateObject("Outlook.Application")  'not this
Set oMail = oApp.CreateItem(olMailItem)
With oMail
    .To = pvTo
    .Subject = pvSubj
   
   
    .Attachments.Add pvFile, olByValue, 1
   
    .HTMLBody = "<BODY>" & pvBody & "<p>&nbsp;</p><IMG src =" & pvFile & "</BODY>"
   
     'test with this
    .Display True
   
      'to send email, use this:
    '.Send
End With
Send1Email = True
endit:
Set oMail = Nothing
Set oApp = Nothing
Exit Function
ErrMail:
MsgBox Err.Description, vbCritical, Err
Resume endit
End Function

Function GetApplication(className As String) As Object
' function to encapsulate the instantiation of an application object
Dim theApp As Object
On Error Resume Next
Set theApp = GetObject(, className)
If Err.Number <> 0 Then
    MsgBox "Unable to Get" & className & ", attempting to CreateObject"
    Set theApp = CreateObject(className)
End If
If theApp Is Nothing Then
    Err.Raise Err.Number, Err.Source, "Unable to Get or Create the " & className & "!"
    Set GetApplication = Nothing
End If
'MsgBox "Successfully got a handle on Outlook Application, returning to caller"
Set GetApplication = theApp
End Function

Public Sub collectEmailList()
Dim vTo, vWord, vName, vEmail
On Error GoTo errAdd
Set gcolEmails = New Collection
       
        'cycle thru the list of email addrs
Range("D2").Select
While ActiveCell.Value <> ""
    vEmail = ActiveCell.Offset(0, 0).Value
    vWord = vEmail
        'vName = ActiveCell.Offset(0, 1).Value
        'vWord = vName & "~" & vEmail
   
    gcolEmails.Add vEmail, vWord      'add email to collection
    ActiveCell.Offset(1, 0).Select 'next row
Wend
 'free memory
'Set gcolEmails = Nothing
Exit Sub
errAdd:
If Err = 457 Then Resume Next   'prevent error for dupes
MsgBox Err.Description, , Err
Exit Sub
Resume
End Sub

Public Sub SendAllEmails()
Dim i As Integer
Dim vEmail, vName, vSubj, vBody, vFile
SetWarnings False
collectEmailList
For i = 1 To gcolEmails.Count
   vName = ""
   vEmail = gcolEmails(i)
      'EMAIL THE DATA
    vSubj = Range("G10").Value
    vBody = Range("G12").Value
    vFile = Range("G14").Value
   
    Send1Email vEmail, vSubj, vBody, vFile
Next
SetWarnings True
End Sub
Private Sub SetWarnings(ByVal pbOn As Boolean)
   Application.DisplayAlerts = pbOn    'turn off sheet compatability msg
   Application.EnableEvents = pbOn
   Application.ScreenUpdating = pbOn
End Sub
 
Upvote 0
Hi Ranman,
thanks for your help,
I might struggle with the "NOTE : YOU MUST HAVE THE OUTLOOK X.x Object Library" part as i'm not the only one using the document
does anyone have a way to do this without needing this step?
or is there a way to switch this on with a macro?

thanks

Tony
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

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