我得到了下面的Excel中運行時錯誤VBA代碼刪除發件人郵件如何刪除從Outlook
Sub Worksheet_Change(ByVal Target As Range)
Dim PriorVal As String
' For the worksheet AuditLog
With Sheets("AuditLog")
If Selection(1).Value = "" Then
PriorVal = "Blank"
Else
PriorVal = Selection(1).Value
End If
Set OutlookApp = CreateObject("Outlook.Application")
Set OlObjects = OutlookApp.GetNamespace("MAPI")
Set newmsg = OutlookApp.CreateItem(olMailItem)
'add recipients
newmsg.Recipients.Add ("add your mail id")
'add subject
newmsg.Subject = ("AuditLog has a violator") '"," Environ("UserName"), Environ("ComputerName"), & sh.Name "
'add body
newmsg.Body = Application.UserName & " has made changes to the AuditLog _ tab at cell position " & Target(1).Address & ", " & Target(1).Value
newmsg.Display 'display
newmsg.Send 'send message
newmsg.DeleteAfterSubmit = True
End With
Set newmsg = Nothing: Set OutlookApp = Nothing:
End Sub
你好Mrbungle,我已經嘗試過,但仍然可以在發送的項目下有一個例外的郵件。謝謝! – USA