Páginas

viernes, 30 de enero de 2015

VBA Excel: Enviar mail automaticamente cuando ocurra un error en la Macro

La clave es err.Description

sub x ()

On Error GoTo oops:

'CODIGO VA AQUI

Exit Sub

oops:
Dim ol As Outlook.Application
Set ol = New Outlook.Application
Set mail = ol.CreateItem(olMailItem)

With mail
    .to = "ruben.torres@huawei.com"
    .Subject = "Error in HTM Status Report."
    .Body = "An error was detected in the application. Please check it: " & vbNewLine & "'" & err.Description & "'"
    .Send
End With

MsgBox ("There was a problem with the execution, the server may be turned off. An error report has been sent to ruben.torres@huawei.com")

End Sub

No hay comentarios:

Publicar un comentario