Solved

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

Posted on 2014-04-25
6
258 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

762 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