PDA

View Full Version : [SOLVED] email via outlook from excel



pdeshazier
06-02-2008, 09:02 AM
can you, via a formula or macro, invoke outlook and send an email from excel?:help

Bob Phillips
06-02-2008, 10:51 AM
AN example




Dim oOutlook As Object
Dim oMailItem As Object
Dim oRecipient As Object
Dim oNameSpace As Object


Set oOutlook = CreateObject("Outlook.Application")
Set oNameSpace = oOutlook.GetNameSpace("MAPI")
oNameSpace.Logon , , True


Set oMailItem = oOutlook.CreateItem(0)
Set oRecipient = _
oMailItem.Recipients.Add("bob.phillips@somewhere.com")
oRecipient.Type = 1 '1 = To, use 2 for cc
'keep repeating these lines with
'your names, adding to the collection.
With oMailItem
.Subject = "The extract has finished."
.Body = "This is an automatic email notification"
' .Attachments.Add ("filename") 'you only need this if
'you are sending attachments?
.Display 'use .Send when all testing done
End With

pdeshazier
06-02-2008, 11:39 AM
thanks, but how do i tell it which email address to use based on the value of a cell?

pdeshazier
06-02-2008, 01:03 PM
for instance, i'll have a workbook which has account errors listed, along with department directors' names in a cell on each row. i will need to email a range of data on the spreadsheet to whomever the director for that dept is (i can include their email address on each row if necessary). can you tell me how to accomplish this? thanks.

Bob Phillips
06-02-2008, 01:59 PM
Show us an example workbook.

pdeshazier
06-02-2008, 02:14 PM
i've attached a spreadsheet. the department dir email is who the recipient of each row's data will be, so i need to be able to read column H and grab each row that value exists on, then when the value in col H changes, launch an email. so, i need the macro to select rows 2-7 and email to heather.mcmurray@sumner.org, then select row 8 and email to cindy.oneal@sumner.org, then email the remaining rows to mandy.thompson@sumner.org and so on.

figment
06-02-2008, 02:56 PM
i do a similar things with reports at my office, and with the help of some code from this site, i got it to work. this code relys on there bing a table that has everybodys/deppartemt listed, along with there email address. for my poupoues i keep this table on a hidden sheet with in the same workbook, but you can put it anywhere you like. i have addapted the code to fit your formate.

8922

i hope this helps

pdeshazier
06-04-2008, 06:53 AM
YOU'RE GENIUS! love it! how can i invoke it from a button on the spreadsheet rather than opening vb editor and running it???? thanks soooooo much

pdeshazier
06-04-2008, 07:54 AM
one more question: i need the "from" user to be from a different email address than that of the user signed on. is there a way to set this? thanks so much for your help

Bob Phillips
06-04-2008, 09:48 AM
You will have to sign in to that profile, the oNameSpace.Logon is where you do that.

pdeshazier
06-05-2008, 08:37 AM
one more question. when the code creates each email, how can i timestamp each row, say, in column H? thanks.

pdeshazier
06-05-2008, 08:38 AM
test

pdeshazier
07-22-2008, 12:59 PM
i created this workbook in 2007 and saved as 2003 (.xls); however, i can't get it to run on users' PCs which have 2003 - i get 'error loading DLL.' do you know how to resolve this?

pdeshazier
07-22-2008, 01:08 PM
also, how does 'whoto' work. is this a table name?

pdeshazier
12-16-2013, 08:10 AM
i posted this several years ago. how can i locate the spreadsheet i had attached in my post? thanks.

Kenneth Hobs
12-16-2013, 08:23 AM
Only post 7 has an attachment.

pdeshazier
12-16-2013, 09:02 AM
Thanks. I'll start a new post.