Discussion Locked

Emailing from Excel.

0 helpful
12 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Does anyone know some code for automatically emailing files to
people that are contained within a spreadsheet. ie the code should recurse
through the names pick up the first one send them the relevant file then
back to excel pick up the next nameand send it to the person. Any help
would be extremely helpful.

12 replies

by corky132

I dont believe it can be done in excel.. If you use SQL you can create a trigger and do sort of what you want.. however you lose the functionality of a spreadsheet...

by mcorr

You can use the mail merge feature of Word to use the Excel spreadsheet as the source for your recipients. See the office help page titled "Use Microsoft Excel data as a mailing list in Word".

As far a doing it programmically, it is possible butdifficult. You could write a VBA program to make MAPI calls on a range of cells, but that may incur too much work. See Knowledge Base article Q180631 for information.

by msheehan

Yes, this can be done with VB - its not too complicated, but far longer than will fit in this box.

Check out two books -
Programming Outlook and Exchange
Step by Step Visual Basic 6

Those will give you the foundation to write this program.

-Mike

by jmusgrov

The DoCmd.SendObject command may be useful here. I used it in Access. Create variables for identifying the object to be sent and the recipient. Assuming the recipient name and file name are in rows, create a loop that starts at the first row, sets the variables to the cells' contents, executes the DoCmd and then moves to the next row.

by tclere

If you use Outlook, it is a piece of cake.
Just add MS Outlook Object Library to your project references. I have an Excel application that I use to send update messages internal to our organization. Let me know if you need more help!

Public Type eMailInfo
sTo(6) As String
Subject As String
Message As String
End Type

Public eMail As eMailInfo

Public Sub SendMailMessage()
Dim olApp As Object, olItem As Object, i As Integer, sCCList As String
Set olApp = CreateObject("Outlook.Application")
Set olItem = olApp.CreateItem(olMailItem)
i = 0
Do While (Len(eMail.sTo(i))) > 0
olItem.Recipients.Add eMail.sTo(i)
i = i + 1
Loop
olItem.Subject = eMail.Subject
olItem.Body = eMail.Message
olItem.DeleteAfterSubmit = True
olItem.OriginatorDeliveryReportRequested = False
olItem.ReadReceiptRequested = False
olItem.Send
For i = 0 To 6: eMail.sTo(i) = "": Next i 'clear list of addresses
EndSub

Sub Main
'T

by tclere

Here is the rest of the sample:

Sub Main
'The sTo() array can be filled manually or by scanning cells
eMail.sTo(1) = "person@place.com"
eMail.Subject = "Some subject"
eMail.Message = "Message Text Goes Here"
Call SendMailMessage
End Sub

This discussion is closed to new replies.