Bulk Emails with multiple variations

ComputerNewbie1992

New Member
Joined
Jul 26, 2018
Messages
16
Hi All,

I have an idea of what I would like the spreadsheet to do however I have ZERO experience with VBA or coding and I've relied heavily on formulas in the past. I've created an example spreadsheet to try to explain what I'm trying to achieve but basically, I'm looking for a spreadsheet which works as follows:
  • Tick boxes of companies you want to send email to - if multiple are ticked, then multiple emails will be sent.
  • 'Point of Contact' and 'Date' will be referred to in the email body.
  • Press [Send] will provide a draft email which can be checked before sending.
    (In the past I've been unable to populate my default signature, as this will be utilised by different members of my team, I cannot have the signature as part of the email body)
Sorry I can't upload a Mini-sheet as my companies admin permissions are restrictive but I can send a copy of the spreadsheet via email if it'll be helpful.

Thanks in advance :)
Greg

To:[Emails addresses associated with Company #]
Cc:Boss@outlook.com
Subject:[Generated from Cell]
Email Body:Hi [Point of Contact],

We wanted to let you know about an exciting product which we are looking to release to the market.

Please provide your RSVP by [Date] to register your interest

Regards
[Signature]
 

Attachments

  • Example.PNG
    Example.PNG
    30.5 KB · Views: 35
Those details come from cells within the sheet so I would guess that the layout of the form isnt as you first posted (I can see it has shifted by 1 cell on each post). Rather than back and forth supply the following info and I will amend the code.

Cell reference for PoC
Cell Reference for the first cell of your email body
Thanks, sorry for the back and forth.

Cell reference for PoC - Starts at F10 ends at F57
Cell Reference for the first cell of your email body - C4
 
Upvote 0

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Thanks, sorry for the back and forth.

Cell reference for PoC - Starts at F10 ends at F57
Cell Reference for the first cell of your email body - C4
that's why the code is failing, those references are nothing like the sample provided. In order to provide the correct response you would need to add the workbook so the code can be amended properly. Alternatively you can try amending the code yourself so that

VBA Code:
.HTMLBody = rng.Offset(, 3) & "<br><br>" & range("B15").value  <-- B15 needs to reflect the cell where the words "We wanted to let you know" are located

If your Poc starts at F10 the presumably your company will also be in the same row at C10 so the code will need to reflect that in the line "For each cell in range"
 
Upvote 0
that's why the code is failing, those references are nothing like the sample provided. In order to provide the correct response you would need to add the workbook so the code can be amended properly. Alternatively you can try amending the code yourself so that

VBA Code:
.HTMLBody = rng.Offset(, 3) & "<br><br>" & range("B15").value  <-- B15 needs to reflect the cell where the words "We wanted to let you know" are located

If your Poc starts at F10 the presumably your company will also be in the same row at C10 so the code will need to reflect that in the line "For each cell in range"
Example (GW).xlsm
BCDEFGHIJ
2Email Subject:New release coming soon
3
4Email Body:[Test]
5
6
7
8Whole Market?Specific Markets
9
10Company AxPoCMarkCompany A
11Company B PoCSteveCompanyA1@outlook.com
12Company C PoCTeamCompanyA2@outlook.com
13Company D PoCTeam
14Company E PoCTeam
15Company F PoCJane
16Company G PoCTeam
17Company H PoCTeam
18Company I PoCTeamCompany B
19Company J PoCTeamCompanyB1@outlook.com
20Company K PoCTeamCompanyB2@outlook.com
21Company L PoCTeam
22Company M PoCTeam
23Company N PoCTeam
24Company O PoCTeam
25Company P PoCTeam
26Company Q PoCTeamCompany C
27Company R PoCTeamCompanyC1@outlook.com
28Company S PoCTeamCompanyC2@outlook.com
29Company T PoCTeam
30Company U PoCTeam
31Company V PoCTeam
32Company W PoCTeam
33Company X PoCTeam
34Company Y PoCTeamCompany D
35Company Z PoCTeamCompanyD1@outlook.com
36Company AA PoCTeamCompanyD2@outlook.com
37Company AB PoCTeam
38Company AC PoCTeam
39Company AD PoCTeam
40Company AE PoCTeam
41Company AF PoCTeam
42Company AG PoCTeamCompany E
43Company AH PoCTeamCompanyE1@outlook.com
44Company AI PoCTeamCompanyE2@outlook.com
45Company AJ PoCTeam
46Company AK PoCTeam
47Company AL PoCTeam
48Company AM PoCTeam
49Company AN PoCTeam
50Company AO PoCTeamCompany F
51Company AP PoCTeamCompanyF1@outlook.com
52Company AQ PoCTeamCompanyF2@outlook.com
53Company AR PoCTeam
54Company AS PoCTeam
55Company AT PoCTeam
56Company AU PoCTeam
57Company AV PoCTeam
58Company G
59CompanyG1@outlook.com
60CompanyG2@outlook.com
61
Email list
Cell Formulas
RangeFormula
C11:C57C11=IF($C$8="Full Market","x","")
Cells with Data Validation
CellAllowCriteria
C8:E8ListFull Market, Specific Markets
C10:C57Listx,


------------------

Sub CreateEmails()
Application.ScreenUpdating = False
Dim OutApp As Object, OutMail As Object, rng As Range, fnd As Range, x As Long, Signature As String
Set OutApp = CreateObject("Outlook.Application")
For Each rng In Range("C10", Range("C" & Rows.Count).End(xlUp))
If rng = "x" Then
Set fnd = Range("J:J").Find(rng.Offset(, -1).Value, LookIn:=xlValues, lookat:=xlWhole)
If Not fnd Is Nothing Then
x = fnd.CurrentRegion.Offset(1).Cells.Count - 1
Set OutMail = OutApp.CreateItem(0)
With OutMail
.display
Signature = OutMail.HTMLbody
.To = Join(Application.WorksheetFunction.Transpose(Range("J" & fnd.Row + 1).Resize(x).Value), ";")
.cc = "Boss@outlook.com"
.Subject = Range("C2").Value
.HTMLbody = .HTMLbody = rng.Offset(, 3) & "<br><br>" & "We wanted to let you know about an exciting product which we are looking to release to the market." & "<br><br><br><br>" & "Regards,"
.HTMLbody = .HTMLbody & Signature
.display
End With
End If
End If
Next rng
Application.ScreenUpdating = True
End Sub
 
Upvote 0
The below code works exactly as you want based on the sheet you supplied above. If you re arrange it or move anything around you will need to alter the vba code reference to it. The reason I think it was failing before is because you had double up on the "=" on the line below your subject.
Incidentally if specific market is selected and you then select any cell from C11 downwards with an x you will be overwriting your cell formula. You may be better setting that as a conditional format.

Heres your code
VBA Code:
Sub CreateEmails()

Application.ScreenUpdating = False

Dim OutApp As Object, OutMail As Object
Dim rng As range, fnd As range
Dim x As Long
Dim Signature As String

Set OutApp = CreateObject("Outlook.Application")

For Each rng In range("C10", range("C" & Rows.Count).End(xlUp))
    
    If rng = "x" Then

    Set fnd = range("J:J").Find(rng.Offset(, -1).Value, LookIn:=xlValues, lookat:=xlWhole)
        If Not fnd Is Nothing Then

        x = fnd.CurrentRegion.Offset(1).Cells.Count - 1

        Set OutMail = OutApp.CreateItem(0)
            With OutMail
              .display
              Signature = OutMail.HTMLbody
              .To = Join(Application.WorksheetFunction.Transpose(range("J" & fnd.Row + 1).Resize(x).Value), ";")
              .cc = "Boss@outlook.com"
              .Subject = range("C2").Value
              .HTMLbody = "Hi " & rng.Offset(, 3) & "," & "<br><br>" & range("C4") & "<br><br><br><br>" & "Regards,"
              .HTMLbody = .HTMLbody & Signature
              .display
            End With
        End If
    End If

Next rng

Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
The below code works exactly as you want based on the sheet you supplied above. If you re arrange it or move anything around you will need to alter the vba code reference to it. The reason I think it was failing before is because you had double up on the "=" on the line below your subject.
Incidentally if specific market is selected and you then select any cell from C11 downwards with an x you will be overwriting your cell formula. You may be better setting that as a conditional format.

Heres your code
VBA Code:
Sub CreateEmails()

Application.ScreenUpdating = False

Dim OutApp As Object, OutMail As Object
Dim rng As range, fnd As range
Dim x As Long
Dim Signature As String

Set OutApp = CreateObject("Outlook.Application")

For Each rng In range("C10", range("C" & Rows.Count).End(xlUp))
   
    If rng = "x" Then

    Set fnd = range("J:J").Find(rng.Offset(, -1).Value, LookIn:=xlValues, lookat:=xlWhole)
        If Not fnd Is Nothing Then

        x = fnd.CurrentRegion.Offset(1).Cells.Count - 1

        Set OutMail = OutApp.CreateItem(0)
            With OutMail
              .display
              Signature = OutMail.HTMLbody
              .To = Join(Application.WorksheetFunction.Transpose(range("J" & fnd.Row + 1).Resize(x).Value), ";")
              .cc = "Boss@outlook.com"
              .Subject = range("C2").Value
              .HTMLbody = "Hi " & rng.Offset(, 3) & "," & "<br><br>" & range("C4") & "<br><br><br><br>" & "Regards,"
              .HTMLbody = .HTMLbody & Signature
              .display
            End With
        End If
    End If

Next rng

Application.ScreenUpdating = True
End Sub
Amazing, thanks so much!
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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