PDA

View Full Version : SOLVED: Send email using vbs without attachment



tilamok
03-20-2011, 11:23 AM
Hi All

I am starting a project where I will be writing a series of macros.

When 1 macro ends, I wish to automatically send a mail to myself using vba, without attachment, with the subject being eg "Macro X finished at hh:mm:ss"

This is to have some audit control and to monitor if a macro has failed at a particular stage.

Please could someone give me a starting position. I'm using outlook 2003

Thanks in advance

mdmackillop
03-20-2011, 11:42 AM
Sub MyMacro()
Dim I, X
Dim msg As String
For I = 1 To 1000000
X = X + 1
Next
If Not Err = 0 Then
msg = Err & ": " & Err.Description
Else
msg = "No Errors"
End If
Call SendAudit(msg, Now, "MyMacro")
End Sub




Sub SendAudit(msg As String, tim As Date, macro As String)
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Dim c As Range
Dim FirstAddress As String

Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")

Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.to = "md@vbax.com"
.Subject = "Macro " & macro & " finished at " & Format(tim, "hh:mm:ss")
.Body = msg
.Display 'or .Send
End With
Set OutMail = Nothing
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub

tilamok
03-20-2011, 11:44 AM
Thank you very much

I'll give it a try