|
Subject:
|
Send Mail thru Excel Macro
|
|
Posted By:
|
Abhinav
|
Post Date:
|
1/10/2006 1:39:42 AM
|
Hi,
I want to send a email thru macro, whenever a process is over. Is it possible? Currently I am using Microsoft Outlook 2000 & Excel 2000.
I had gone thur the listed quires & found none to help me out
thanks Abhinav
|
|
Reply By:
|
maccas
|
Reply Date:
|
1/10/2006 4:35:57 AM
|
Try this. You'll need to add a reference to Outlook in your Visual Basic Project (Tools -> References... -> Microsoft Outlook)
Sub SendEmail()
Dim OlApp As New Outlook.Application
Dim myNameSp As Outlook.Namespace
Dim myInbox As Outlook.MAPIFolder
Dim myExplorer As Outlook.Explorer
Dim NewMail As Outlook.MailItem
Dim OutOpen As Boolean
' Check to see if there's an explorer window open
' If not then open up a new one
OutOpen = True
Set myExplorer = OlApp.ActiveExplorer
If TypeName(myExplorer) = "Nothing" Then
OutOpen = False
Set myNameSp = OlApp.GetNamespace("MAPI")
Set myInbox = myNameSp.GetDefaultFolder(olFolderInbox)
Set myExplorer = myInbox.GetExplorer
End If
'myExplorer.Display ' You don't have to show Outlook to use it
' Create a new mail message item.
Set NewMail = OlApp.CreateItem(olMailItem)
With NewMail
'.Display ' You don't have to show the e-mail to send it
.Subject = "Look at this!"
.To = "name@wherever.com"
.Body = "This is a demonstration"
End With
'NewMail.Send
If Not OutOpen Then OlApp.Quit
'Release memory.
Set OlApp = Nothing
Set myNameSp = Nothing
Set myInbox = Nothing
Set myExplorer = Nothing
Set NewMail = Nothing
End Sub
|
|
Reply By:
|
jeilan_h
|
Reply Date:
|
5/22/2006 3:58:00 AM
|
Hi,
Any idea about the macro to send email with a file as attachment? for example : "c:\tes\finance.pdf"
Thank you, Jeilan
quote: Originally posted by maccas
Try this. You'll need to add a reference to Outlook in your Visual Basic Project (Tools -> References... -> Microsoft Outlook)
Sub SendEmail()
Dim OlApp As New Outlook.Application
Dim myNameSp As Outlook.Namespace
Dim myInbox As Outlook.MAPIFolder
Dim myExplorer As Outlook.Explorer
Dim NewMail As Outlook.MailItem
Dim OutOpen As Boolean
' Check to see if there's an explorer window open
' If not then open up a new one
OutOpen = True
Set myExplorer = OlApp.ActiveExplorer
If TypeName(myExplorer) = "Nothing" Then
OutOpen = False
Set myNameSp = OlApp.GetNamespace("MAPI")
Set myInbox = myNameSp.GetDefaultFolder(olFolderInbox)
Set myExplorer = myInbox.GetExplorer
End If
'myExplorer.Display ' You don't have to show Outlook to use it
' Create a new mail message item.
Set NewMail = OlApp.CreateItem(olMailItem)
With NewMail
'.Display ' You don't have to show the e-mail to send it
.Subject = "Look at this!"
.To = "name@wherever.com"
.Body = "This is a demonstration"
End With
'NewMail.Send
If Not OutOpen Then OlApp.Quit
'Release memory.
Set OlApp = Nothing
Set myNameSp = Nothing
Set myInbox = Nothing
Set myExplorer = Nothing
Set NewMail = Nothing
End Sub
|
|
Reply By:
|
neochichiri
|
Reply Date:
|
5/24/2006 1:12:33 PM
|
quote: Originally posted by jeilan_h
Hi,
Any idea about the macro to send email with a file as attachment? for example : "c:\tes\finance.pdf"
Thank you, Jeilan
Yes, after .body add the following line: .Attachments.Add ("C:\tes\finance.pdf")
That should work for you.
|
|
Reply By:
|
jeilan_h
|
Reply Date:
|
6/21/2006 2:15:04 AM
|
Frends,
Seems like the macro just run for Microsoft outlook. Is there any method to send the email through outlook express6 ?
Thanx.
|
|
Reply By:
|
maccas
|
Reply Date:
|
7/3/2006 6:17:25 AM
|
Jeilan,
You're right - this code is only for Outlook. There is no comparable code for Outlook Express.
Have a look at an earlier post of mine for more info on this issue: http://p2p.wrox.com/topic.asp?TOPIC_ID=40487
Maccas
|
|
Reply By:
|
chuls
|
Reply Date:
|
9/21/2006 10:09:15 AM
|
when i ran this code..i got a pop up from Outlook saying "a program is trying to send a mail. do you wish to continue?" YES NO HELP
is thr any way we cud avoid this pop up?
thanks in advance
|
|
Reply By:
|
lanewalk
|
Reply Date:
|
9/22/2006 3:36:16 AM
|
Not easily, and it is really annoying if you are trying to send 100 e-mails. It is a feature of the Outlook Security Update. You can buy software that will switch off the security update whilst you send e-mails but I haven't tried these. There is the option to "Allow access for XX Minutes" which will reduce the number of clicks from 4 to 2 per e-mail which is still a pain.
|