CheckOutlookAndSendEmail
Sub MailViaOutlook() Dim OutApp Dim OutMail Set OutApp = CreateObject ( "Outlook.Application" ) Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.to = "youremailid"
.CC = ""
.BCC = ""
.Subject = "your Subject"
.Body =" Thanks - .......:)"
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
Sub
' Outlook
sub OpenOutlook()
Dim WshShell
Set WshShell=WScript.CreateObject("WScript.Shell")
WshShell.run "Outlook"
If Err <> 0 then
Err.Clear
Set ObjOL= CreateObject("Outlook.Application")
End If
End sub
'End Function OpenOutlook
Sub CheckOutlookAndSendEmail()
dim Process, strObject, strProcess
Const strComputer = "."
strProcess = "OUTLOOK.exe"
strObject = "winmgmts://" & strComputer
For Each Process in GetObject( strObject ).InstancesOf( "win32_process" )
If UCase( Process.name ) = UCase( strProcess ) Then
call MailViaOutlook ' no need to open outlook as it is already open, Hence using the exesting and send email
exit sub
end if
Next
call OpenOutlook ' Open Outlook
call MailViaOutlook ' send email using outlook
end,
Sub