Wednesday, March 21, 2007

send mails from excel

just did this today, seems like something useful: it allows you to send emails from excel 2003, provided your default MAPI client is configured on your windows system.

this example sends an email with the text "hello".

here's how i did it:

1. configure outlook or outlook express for sending emails

2. in an excel file:
view -> toolbars -> control toolbox
more controls -> microsoft mapi session -> (insert into sheet1)
more controls -> microsoft mapi message -> (insert into sheet1)
tools -> macros -> visual basic editor
insert -> module

3. enter into the module:
Public Sub sendEmail()
Dim emailAddr As String
emailAddr = ActiveCell.Text
Sheet1.MAPISession1.SignOn
With Sheet1.MAPIMessages1
.SessionID = Sheet1.MAPISession1.SessionID
MsgBox .SessionID
.Compose
.RecipAddress = emailAddr
.MsgNoteText = "Hello"
.RecipType = 1
.ResolveName
.Send 0
End With
Sheet1.MAPISession1.SignOff
End Sub

4. close the visual basic editor, go back to excel
5. enter an email address anywhere in the excel file, and select that cell
6. tools -> macros -> macros -> sendEmail -> run
7. click away any security warnings :)

No comments:

popular posts