Automatic Email sending from Excel

pareek.ashwani

New Member
Joined
Feb 25, 2008
Messages
6
hello people i just need a small help.

See i have a Excel 2003 file in which 1st column is of name, 2nd is of email id, 3rd is of Date of birth.

like this

Name | Email id | DOB
-------|-----------------|------
Jhon | jhon@test.com | 15/3/1987
Sam | sam@test.com | 13/12/1984



ok

i also have a well working Microsoft office outlook 2003 in the same computer.

now i want a method that every morning it sends a automatic birthday wish formate.
in which it changes the name from the list and sends it to the person whose birthday is this and sends a CC to all the other in the list..


Macro ,,
free software what ever u know please tell me
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

whitesabbathica9

New Member
Joined
Jun 3, 2008
Messages
47
Have you resolved your issue?

If you are able to benefit from anything in the thread, please provide feedback. It's good to know if information provided is useful, or if maybe you found something else out that could assist others.

I am interested in accomplishing a similar task in the future. If you are able to find code, please post.
 

Zack Barresse

MrExcel MVP
Joined
Dec 9, 2003
Messages
10,881
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
  3. Web

ADVERTISEMENT

Hi there!

To do this automatically, without any assistance at all, you'll have to do a few things. You're using Office 2003 so you have Windows, I'm assuming Windows XP? Well, assuming so, you'll need the following items:

  • A text file saved as VBS set to Windows Scheduler
  • A standard module with the necessary coding in an Excel file
  • The ClickYes program (free) downloaded/installed*
* The code I'll supply utilizes the ClickYes program. It's free and works well with Outlook 2003. You do not have to use this program if you don't want to. If you do not want to use it, the code will not work and will need to be adjusted.


So, open up Notepad and paste the following code:
Edit: Change the path in the code below to suit your specific needs!!!
Code:
'/// Declare variables
Dim xlApp
Dim wb
Dim ws
dim blnAppOpen
dim blnWbOpen
dim sPath
dim sName
'/// Check for application existence, create
on error resume next
set xlapp = getobject(, "Excel.Application")
blnAppOpen= True
if xlapp is nothing then
    set xlapp = createobject("Excel.Application")
    blnAppOpen= False
end if
'//////////////////////////////////////////////////////////////////////////////
'/// Open Workbook ////////////////////////////////////////////////////////////
sPath = "C:\Documents and Settings\Z\Desktop\"
sName = "TESTBOOK.xls"
'//////////////////////////////////////////////////////////////////////////////
set wb = xlApp.workbooks(sName)
blnWbOpen = True
if wb is nothing then
    set wb = xlApp.workbooks.open(sPath & sName)
    blnWbOpen = False
end if
'//////////////////////////////////////////////////////////////////////////////
'/// Run routines /////////////////////////////////////////////////////////////
xlapp.run "SendBirthdayWishes"
'//////////////////////////////////////////////////////////////////////////////

'/// Quit
if blnWbOpen = False then wb.close
if blnAppOpen= False then xlApp.quit


You can save this file with whatever name you want, in whatever location you want, so long as it's on the same C: drive as the Excel file. NOTE: you'll have to type the extension ".vbs" after the file name. The icon should change from a Notepad-type icon to a VBS-type icon (the little blue script on top of a white sheet). THIS IS NORMAL.


Now in your Excel file, you'll need to make sure you insert a standard module. So open the VBE (Visual Basic Editor) with Alt + F11. Then insert your Standard Module (Alt + I, S). In that code window that pops up, paste the following code:

Edit: Change any of the code below to suit your specific needs (i.e. mail body)!!!
Code:
Option Explicit

Sub SendBirthdayWishes()
    Dim OL As Object, olMail As Object, blnOpened As Boolean
    Dim ws As Worksheet, c As Range, i As Long, j As Long
    Dim k As Long, arrData(1 To 1000, 1 To 3) As Variant
    Dim sBody As String, objwShell As Object
    Application.ScreenUpdating = False
    Set ws = ThisWorkbook.Worksheets("Sheet1")
    For Each c In ws.Range("C2:C" & ws.Cells(ws.Rows.Count, 3).End(xlUp).Row)
        If Month(c.Value) = Month(VBA.Date()) And Day(c.Value) = Day(VBA.Date()) Then
            i = i + 1
            arrData(i, 1) = c.Offset(0, -2).Value
            arrData(i, 2) = c.Offset(0, -1).Value
            arrData(i, 3) = c.Value
        End If
    Next c
    If IsEmpty(arrData(1, 1)) Then Exit Sub
    On Error Resume Next
    Set objwShell = CreateObject("wscript.shell")
    objwShell.Run ("""C:\Program Files\Express ClickYes\ClickYes.exe"" -activate")
    Set OL = GetObject(, "Outlook.Application")
    If OL Is Nothing Then
        Set OL = CreateObject("Outlook.Application")
        blnOpened = True
    End If
    On Error GoTo 0
    For j = LBound(arrData) To UBound(arrData)
        If IsEmpty(arrData(j, 1)) Then Exit For
        Set olMail = OL.CreateItem(0)
        olMail.to = arrData(j, 2)
        For k = LBound(arrData) To UBound(arrData)
            If IsEmpty(arrData(k, 1)) Then Exit For
            olMail.Cc = arrData(k, 2) & "; "
        Next k
        olMail.Subject = "Happy Birthday!"
        sBody = "Just wanted to wish you a happy birthday when you turn "
        sBody = sBody & Year(arrData(j, 3)) - Year(VBA.Date()) & "!"
        sBody = sBody & vbNewLine & vbNewLine
        sBody = sBody & "Marco" 'Signature line
        olMail.Body = sBody
        olMail.Send
    Next j
    objwShell.Run ("""C:\Program Files\Express ClickYes\ClickYes.exe"" -stop")
    ThisWorkbook.Saved = True
    Application.ScreenUpdating = True
End Sub


Now you'll need to download/install the ClickYes program. Here is a link:

http://www.contextmagic.com/express-clickyes/free-version.htm
Direct download: http://www.contextmagic.com/ftp/ClickYesSetup.exe


You'll have to open up Windows Scheduler and add the VBS file as a daily task at whatever time you want it to run at. So long as your computer is turned on, it will run automatically. To open Scheduled Tasks, click Start, click All Programs, point to Accessories, point to System Tools, and then click Scheduled Tasks.


Please post back with any questions or comments.


HTH
 

nitulkumar

New Member
Joined
Jan 10, 2014
Messages
3
Hi there!

To do this automatically, without any assistance at all, you'll have to do a few things. You're using Office 2003 so you have Windows, I'm assuming Windows XP? Well, assuming so, you'll need the following items:

  • A text file saved as VBS set to Windows Scheduler
  • A standard module with the necessary coding in an Excel file
  • The ClickYes program (free) downloaded/installed*
* The code I'll supply utilizes the ClickYes program. It's free and works well with Outlook 2003. You do not have to use this program if you don't want to. If you do not want to use it, the code will not work and will need to be adjusted.


So, open up Notepad and paste the following code:
Edit: Change the path in the code below to suit your specific needs!!!
Code:
'/// Declare variables
Dim xlApp
Dim wb
Dim ws
dim blnAppOpen
dim blnWbOpen
dim sPath
dim sName
'/// Check for application existence, create
on error resume next
set xlapp = getobject(, "Excel.Application")
blnAppOpen= True
if xlapp is nothing then
    set xlapp = createobject("Excel.Application")
    blnAppOpen= False
end if
'//////////////////////////////////////////////////////////////////////////////
'/// Open Workbook ////////////////////////////////////////////////////////////
sPath = "C:\Documents and Settings\Z\Desktop\"
sName = "TESTBOOK.xls"
'//////////////////////////////////////////////////////////////////////////////
set wb = xlApp.workbooks(sName)
blnWbOpen = True
if wb is nothing then
    set wb = xlApp.workbooks.open(sPath & sName)
    blnWbOpen = False
end if
'//////////////////////////////////////////////////////////////////////////////
'/// Run routines /////////////////////////////////////////////////////////////
xlapp.run "SendBirthdayWishes"
'//////////////////////////////////////////////////////////////////////////////

'/// Quit
if blnWbOpen = False then wb.close
if blnAppOpen= False then xlApp.quit


You can save this file with whatever name you want, in whatever location you want, so long as it's on the same C: drive as the Excel file. NOTE: you'll have to type the extension ".vbs" after the file name. The icon should change from a Notepad-type icon to a VBS-type icon (the little blue script on top of a white sheet). THIS IS NORMAL.


Now in your Excel file, you'll need to make sure you insert a standard module. So open the VBE (Visual Basic Editor) with Alt + F11. Then insert your Standard Module (Alt + I, S). In that code window that pops up, paste the following code:

Edit: Change any of the code below to suit your specific needs (i.e. mail body)!!!
Code:
Option Explicit

Sub SendBirthdayWishes()
    Dim OL As Object, olMail As Object, blnOpened As Boolean
    Dim ws As Worksheet, c As Range, i As Long, j As Long
    Dim k As Long, arrData(1 To 1000, 1 To 3) As Variant
    Dim sBody As String, objwShell As Object
    Application.ScreenUpdating = False
    Set ws = ThisWorkbook.Worksheets("Sheet1")
    For Each c In ws.Range("C2:C" & ws.Cells(ws.Rows.Count, 3).End(xlUp).Row)
        If Month(c.Value) = Month(VBA.Date()) And Day(c.Value) = Day(VBA.Date()) Then
            i = i + 1
            arrData(i, 1) = c.Offset(0, -2).Value
            arrData(i, 2) = c.Offset(0, -1).Value
            arrData(i, 3) = c.Value
        End If
    Next c
    If IsEmpty(arrData(1, 1)) Then Exit Sub
    On Error Resume Next
    Set objwShell = CreateObject("wscript.shell")
    objwShell.Run ("""C:\Program Files\Express ClickYes\ClickYes.exe"" -activate")
    Set OL = GetObject(, "Outlook.Application")
    If OL Is Nothing Then
        Set OL = CreateObject("Outlook.Application")
        blnOpened = True
    End If
    On Error GoTo 0
    For j = LBound(arrData) To UBound(arrData)
        If IsEmpty(arrData(j, 1)) Then Exit For
        Set olMail = OL.CreateItem(0)
        olMail.to = arrData(j, 2)
        For k = LBound(arrData) To UBound(arrData)
            If IsEmpty(arrData(k, 1)) Then Exit For
            olMail.Cc = arrData(k, 2) & "; "
        Next k
        olMail.Subject = "Happy Birthday!"
        sBody = "Just wanted to wish you a happy birthday when you turn "
        sBody = sBody & Year(arrData(j, 3)) - Year(VBA.Date()) & "!"
        sBody = sBody & vbNewLine & vbNewLine
        sBody = sBody & "Marco" 'Signature line
        olMail.Body = sBody
        olMail.Send
    Next j
    objwShell.Run ("""C:\Program Files\Express ClickYes\ClickYes.exe"" -stop")
    ThisWorkbook.Saved = True
    Application.ScreenUpdating = True
End Sub


Now you'll need to download/install the ClickYes program. Here is a link:

A program is trying to send e-mail on your behalf. Stop this message with ClickYes.
Direct download: http://www.contextmagic.com/ftp/ClickYesSetup.exe


You'll have to open up Windows Scheduler and add the VBS file as a daily task at whatever time you want it to run at. So long as your computer is turned on, it will run automatically. To open Scheduled Tasks, click Start, click All Programs, point to Accessories, point to System Tools, and then click Scheduled Tasks.


Please post back with any questions or comments.


HTH


Hi Zack Barresse,
your programme is working fine without any error,thanks for sharing such a good topic but I think there should be a
image inserting option which can send the image with the email in body not as attachment.
I have code & want to share with you which has the image inserting option in body of the mail but where to add this code
or adjust with your code I don't know please help me in this regards.
The code is "Sub emailingProgram()
Dim olapp As Outlook.Application
Dim objmail As Outlook.mailitem
Dim pos As Integer
Set olapp = Outlook.Application
For Each xcell In Sheets("Sheet1").Range(Range("tolist"), _
Range("tolist").End(xlDown))
msgText = Range("Msg")
xcell.Activate
ActiveCell.Offset(0, 1).Select
'If you think that the email ID is in the pattern firstname.lastname@mail.com use this if block
'The code will go into the else statement if the First Name is not mentioned
If Selection.Value = "" Then
pos = InStr(1, xcell.Value, ".")
Fname = Mid$(xcell.Value, 1, InStr(1, xcell.Value, ".") - 1)
Else
'If you have mentioned the first names in the First Name column this part will read it directly
Fname = Selection.Value
End If
'For each of the cells present in the To List we create a MailItem and send it
Set objmail = olapp.CreateItem(olMailItem)
objmail.BodyFormat = olFormatRichText
'Setting the subject, I have kept a Happy Birthday, Change as per your wish
objmail.Subject = "Happy Birthday " + UCase(Mid$(Fname, 1, 1)) + Mid$(Fname, 2)

'Uncomment the following line of code in case you want to send a plain message
'objmail.Body = "Hi " + UCase(Mid$(Fname, 1, 1)) + Mid$(Fname, 2) + "," + Chr(13) + Chr(10) + msgText

'For using an image in your mail or an HTML body for styling
objmail.HTMLBody = "Dear " & UCase(Mid$(Fname, 1, 1)) + Mid$(Fname, 2) & "


Wishing you a Wonderful Birthday






Thanks & Regards

_
Nitul Kumar

"
objmail.To = xcell.Value
objmail.Send
Set objmail = Nothing

Next xcell
End Sub"

thanks in advance.
 

funmies

New Member
Joined
Mar 9, 2017
Messages
1
Please I need help. I visited Mail from Excel example pages and was able to see a code that sends an automatic email when a cell reaches a particular value. But I want to modify the code so that the mail stops sending once a particular cell is not empty. How can I do that? Please help it is urgent
 

Watch MrExcel Video

Forum statistics

Threads
1,129,467
Messages
5,636,446
Members
416,919
Latest member
twc2c

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
Top