Solved

Create loop to create emails based off of a list in Excel

Posted on 2014-04-25
6
259 Views
Last Modified: 2014-04-30
Hello,

I would like to create an email for each row in a spreadsheet which does not have a date in the D column (example spreadsheet attached) and I would like it to ignore each row where there is already a date.

Where there is a date I would like to create an email (I have already been thinking about using the code like something  below





Sub Outlook_email_test()

    Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    strbody = "Hi there" & vbNewLine & vbNewLine & _
              "This is line 1" & vbNewLine & _
              "This is line 2" & vbNewLine & _
              "This is line 3" & vbNewLine & _
              "This is line 4"

    On Error Resume Next
    With OutMail
        .To = "test@test.com"
        .CC = ""
        .BCC = ""
        .Subject = "This is the Subject line"
        .Body = strbody
        '.Send
        .Display
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub


But I would like to put the email address in column C in the .to and the first name in the text somewhere in the strbody  which is in column A. It would also be great to put the current date in column D if an email was generated for that row?

would someone be able to help me create the loop and link this to the email and pull that information needed into the email ;)?

Regards,

GISVPN
Email---Dates-based.xlsx
0
Comment
Question by:gisvpn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 33

Assisted Solution

by:Rob Henson
Rob Henson earned 500 total points
ID: 40022848
Have you looked at MS Word mail merge using e-mail option?

That would do this for you without any fancy VBA script. When setting up the merge there is an option to filter certain records on fields within the data so that would get over the date requirement.

However, this wouldn't then add the date for those sent but applying the same filter to the data set would then show blank cells to be populated with simple one off entry in one cell and then fill for remainder that are visible.

Thanks
Rob H
0
 

Assisted Solution

by:gisvpn
gisvpn earned 0 total points
ID: 40022859
Hi Rob,

Thanks for the post - unfortunately this will be part of a wider VBA script and ideally I am looking to use this - the number of emails going out will be relatively large - a few hundred ;)

Regards,

GISVPN
0
 
LVL 33

Assisted Solution

by:Rob Henson
Rob Henson earned 500 total points
ID: 40023003
Hi,

I am not up to scratch with cross application VBA but I know it can be done. SO maybe you could have part of the script open Word and create the mail merge.

Might as well use the tools for their strengths rather than butchering other tools to do the same job.

Similar question here using Excel and Word:

http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_28418615.html

Thanks
Rob H
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

Assisted Solution

by:gisvpn
gisvpn earned 0 total points
ID: 40023138
Hi Rob,

Thanks for the link to the other question - unfortunately the question does include a word document which I cannot use, I am not sure I can use the same technique for what I am doing? Do you have any suggestions on how I can create a loop down the worksheet and use the email script I already have above and add the date ?

GISVPN
0
 

Accepted Solution

by:
gisvpn earned 0 total points
ID: 40023779
Hi All,

Was working at this this afternoon and ended up with this which appears to work great.
Sub Email_Untrained_PM()


Dim PMRow As Integer
Dim ACellValue As String
Dim BCellValue As String
Dim CCellValue As String
Dim JCellValue As String
    
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String





PMRow = 4
 
    Do
    
   
        ACellValue = Sheets("PMs").Cells(PMRow, 1).Value
        BCellValue = Sheets("PMs").Cells(PMRow, 2).Value
        
    
        
       
        If ACellValue = "" Then
            Exit Do
        End If
        
        
                
        CCellValue = Sheets("PMs").Cells(PMRow, 3).Value
        JCellValue = Sheets("PMs").Cells(PMRow, 10).Value

            
        If CCellValue <> "" And JCellValue = "" Then
        
        
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

    strbody = "MESSAGE"
              


    On Error Resume Next
    With OutMail
        .To = CCellValue
        .CC = ""
        .BCC = ""
        .Subject = "some message in subject " & ACellValue & " " & BCellValue & ""
        .HTMLBody = strbody
        '.Send
        .Display
    End With
    On Error GoTo 0
    
    Set OutMail = Nothing
    Set OutApp = Nothing


         
       Sheets("PMs").Cells(PMRow, 10).Value = Now
       End If
       
       PMRow = PMRow + 1
              

    Loop
    




End Sub

Open in new window

0
 

Author Closing Comment

by:gisvpn
ID: 40031580
Please see best solution above
0

Featured Post

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
: Microsoft Office Collaborate for free and online versions of Microsoft  Word, Excel, Powerpoint, OneNote, Onedrive , Email, Calendar etc. In short we can say that Microsoft office is a suite of servers, applications and services developed by  Micr…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question