Ich lasse aus Excel eine Mail versenden... Ich will jetzt, daß das Excel-VBA im Hintergrund wartet, bis die Email wirklich versendet wurde, damit ich prüfen kann, ob die Mail gesendet wurde oder ob vorher Cancel gedrückt wurde... Wie geht das?
Option Explicit
Private Declare Function SetActiveWindow Lib "USER32.DLL" ( _
ByVal hwnd As Long) As Long
Private Declare Function FindWindow Lib "USER32.DLL" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Public Sub prcMail()
Dim myOutlookApplication As Object, myMail As Object
Set myOutlookApplication = CreateObject("Outlook.Application")
Set myMail = myOutlookApplication.CreateItem(0)
With myMail
.To = "abc@xyz.de"
.Subject = "Rücksendung " & ThisWorkbook.Name
.Attachments.Add ThisWorkbook.FullName
On Error Resume Next
.Send
On Error GoTo 0
End With
SetActiveWindow FindWindow("xlMain", vbNullString)
Select Case Err.Number
Case 0
MsgBox "Die Mappe wurde erfolgreich gesendet." & vbLf & vbLf & _
"Ein Kopie der gesendeten Nachricht befindet sich in Ihrem Outlook-Ordner 'Gesendete Objekte'." _
, 64, "Information"
Case 287
MsgBox "Die Mappe wurde nicht gesendet, da Sie den Vorgang abgebrochen haben.", 64, "Hinweis"
Case Else
MsgBox "Fehler: " & CStr(Err.Number) & vbLf & vbLf & Err.Description, 16, "Fehlermeldung"
End Select
Set myMail = Nothing
Set myOutlookApplication = Nothing
ThisWorkbook.Saved = True
End Sub