Mail bei MsgBox
13.03.2021 14:49:10
Andy
Nepomuk hat mir hier schon super geholfen bei meinem Vorhaben. Besten Dank dafür!
Ich habe nun ein Makro, dass eine MsgBox ausgibt, wenn sich der Status einer Zelle in einem bestimmten Bereich vom ursprünglichen Wert "CLOSED" auf "OPEN" oder "ONGOING" ändert. Der User soll also nur auf Closed setzen, wenn wirklich erledigt. Setzt er den Status von Closed auf Open oder Ongoing zurück, kann das kritische Auswirkungen haben.
Nun habe ich noch eingebaut, dass automatisch eine Mail versendet wird, wenn das auftritt. Allerdings sendet die Mail leider immer, wenn sich der Status ändert. Es soll aber nur passieren, wenn die MsgBox aufgerufen wird - weil dann das kritische Ereignis stattfindet. Könnte mal jemand über das Makro schauen, was ich falsch mache? Vielen Dank!!!
Option Explicit
Private mobjCell As Range
Private Sub Worksheet_Change(ByVal Target As Range)
Dim objOutlook As Object
Dim objMail As Object
Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)
If Not Application.Intersect(Range("Q10:Q1000"), Range(Target.Address)) Is Nothing Then _
If Not mobjCell Is Nothing Then If Target.Value = "OPEN" Or Target.Value = "ONGOING" _
Then _
MsgBox "You have been reset the status in Cell " & Target.Address & " from a formerly _
_
_
_
CLOSED Status to OPEN or ONGOING." _
& vbCrLf & vbCrLf & "This can affect the whole xxxx Group Closing Process!" _
& vbCrLf & vbCrLf & "xxxx will be informed automatically by e-mail now. Please contact _
_
_
_
xxxxx", vbCritical, "!!Critical change during closing process!!"
With objMail
.To = "xxxxx.de"
.Subject = "!!Financial closing alert!!"
.Body = "Financial closing alert " & Target.Address & " has been reset from closed status"
.Send
End With
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Application.Intersect(Range("Q10:Q1000"), Range(Target.Address)) Is Nothing Then
If Target.Cells(1, 1).Value = "CLOSED" Then
Set mobjCell = Target
Else
Set mobjCell = Nothing
End If
End If
End Sub