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.