+ Reply to Thread
Results 1 to 2 of 2

Macro to send emails in batches.

  1. #1
    Registered User
    Join Date
    09-03-2013
    Location
    bahrain
    MS-Off Ver
    Excel 2010
    Posts
    1

    Macro to send emails in batches.

    Hello Guys

    I have a macro to send emails from excel, the below macro sends emails with details in the excel sheet.

    The excel sheet has name,email id's,path of the pdf file to attach and body of the email in separate columns.

    What i need help is

    1. To send emails in batches.(10 or 15 emails should be sent with every click.)
    2. Can the macro in excel instruct outlook send the mail automatically rather than the user click on send button.


    Thanks in advance for your time and support.

    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
    Dim strbody As String

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

    Set sh = Sheets("Sheet1")

    Set OutApp = CreateObject("Outlook.Application")

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


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

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

    With OutMail
    .to = cell.Value
    .Subject = "Dear Patrons"
    .Body = strbody
    With ThisWorkbook.Sheets("Sheet1")

    strbody = "Dear Patron" & vbNewLine & vbNewLine & _
    .Range("G2") & vbNewLine & _
    .Range("G3") & vbNewLine & _
    .Range("G4") & vbNewLine & _
    .Range("G5") & vbNewLine & _
    .Range("G6")

    End With

    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

    .Display 'Or use Send
    End With

    Set OutMail = Nothing
    End If
    Next cell

    Set OutApp = Nothing
    With Application
    .EnableEvents = True
    .ScreenUpdating = True
    End With
    End Sub



  2. #2
    Registered User
    Join Date
    09-08-2013
    Location
    Denver
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Macro to send emails in batches.

    I may not be reading your question correctly.. but here is some code I use to automate the sending of email from a web page using VB. This sorts thrugh

    ' Set the mail server configuration
    Set objConfig=CreateObject("CDO.Configuration")
    objConfig.Fields.Item(sendUrl)=2 ' cdoSendUsingPort
    objConfig.Fields.Item(smtpUrl)="relay-hosting.secureserver.net"
    objConfig.Fields.Item(timeoutUrl)=60
    objConfig.Fields.Update
    ' Create and send the mail
    Set objMail=CreateObject("CDO.Message")
    ' Use the config object created above
    Set objMail.Configuration=objConfig
    objMail.From = "[email protected]"
    objMail.To = myemail
    objMail.Subject = "TestSubject " & mySubject
    objMail.TextBody = mailmsg
    objMail.Send

    set objMail = nothing
    set objConfig = nothing

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Trying to send emails with a Macro
    By gracia31 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-19-2013, 04:31 AM
  2. Macro to re-send emails using Outlook
    By zainnofear1987 in forum Outlook Programming / VBA / Macros
    Replies: 1
    Last Post: 06-13-2012, 12:24 PM
  3. Send outlook emails with message in cells to individual emails associated with them
    By abinayan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-21-2011, 06:11 AM
  4. Sending macro emails using excel: Send emails with their passwords.
    By loveisblind in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-12-2009, 03:16 PM
  5. Macro to send automatic emails.
    By shekar goud in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-07-2009, 08:54 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1