我收到以下Excel到VBA代码的运行时错误,以删除发件人邮件
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
答案 0 :(得分:3)
// Create a DateTime instance with .Kind equal to Unspecified;
// use the earliest date that can be represented as a file time.
DateTime dtUnspecified = DateTime.Parse("1601-01-01");
Console.WriteLine(
dtUnspecified.ToFileTime() + "\n" +
dtUnspecified.ToFileTimeUtc()
);
切换这些
180000000000 // 1601-01-01T05:00:00Z - 5 AM UTC
0 // 1601-01-01T00:00:00Z - midnight UTC
答案 1 :(得分:1)
除了@mrbungle写的内容之外,根据经验,一旦调用Send,唯一允许的操作就是取消引用该消息 - 它现在属于假脱机程序。
在消息仍在显示时,也没有理由调用Display(无模式)然后发送Send。如果您正在显示该消息,您是否希望用户单击“发送”按钮?