VBA Outlook Mail .display,录音如果手动发送

我使用VBA从Excel发送电子邮件,并试图logging邮件是否已被发送。 我已经从另一个post的一些代码在这里:

链接

我已经完全按照所描述的创build了这个类,并且添加了一些额外的比特来查看它是否工作,它初始化了,但是没有其他的事情发生 – 即使在发送邮件之后,类仍然以某种方式在后台打开,所以我必须在VBE中停止它。

这里是调用代码:

Sub SendProc2(add As String) Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(0) On Error Resume Next With OutMail .To = add .CC = "" .BCC = "" .Subject = ThisWorkbook.Name .Body = Application.WorksheetFunction.VLookup(Worksheets("Data").Range("B135"), Range("formversion"), 2, False) _ & " Attached:" & vbCrLf & vbCrLf & ThisWorkbook.Name .Attachments.add ActiveWorkbook.FullName .Display 'or use .Send End With Dim CurrWatcher As EmailWatcher Set CurrWatcher = New EmailWatcher Set CurrWatcher.TheMail = OutMail On Error GoTo 0 Set OutMail = Nothing Set OutApp = Nothing Unload UserForm4 End Sub 

这里是名为EmailWatcher的类模块代码:

 Option Explicit Public WithEvents TheMail As Outlook.MailItem Private Sub Class_Terminate() Debug.Print "Terminate " & Now() End Sub Private Sub TheMail_Send(Cancel As Boolean) Debug.Print "Send " & Now() 'enter code here End Sub Private Sub Class_Initialize() Debug.Print "Initialize " & Now() End Sub 

它似乎从来没有注册_Send,我认为这可能是类的对象没有被定义或别的东西,我有这个麻烦,有时我得到警告,目前正在初始化,然后立即终止,不用等待_Send,帮助将不胜感激,而且如果有更多的信息需要,那么让我知道。

在Windows 7上使用Excel 2007,通过我无法控制的疯狂的本地授权networking。

我对VBA也不陌生,但是我从来没有上过类,做过很多标准模块等等。

谢谢,

 Private WithEvents EM As Outlook.MailItem Public Sub INIT(x As Outlook.MailItem) Set EM = x End Sub Private Sub EM_Send(Cancel As Boolean) End Sub 

 Public WATCHER As clsEmailWatch Sub EMAIL() Dim o As Outlook.Application Dim m As Outlook.MailItem Set o = New Outlook.Application Set m = o.CreateItem(olMailItem) Set WATCHER = New clsEmailWatch WATCHER.INIT m m.To = "xyz@abc.com" m.Send End Sub 

希望这可以帮助