本文介绍了如何初始化事件处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在在线.它应该使用我提供的任何附件自动填充我的主题行.代码不运行.
I found this code online. It is supposed to auto populate my subject line with any attachments I provide. The code does not run.
我没有收到错误或任何表明它甚至通过代码的信息.
I don't receive an error or anything that suggests its even going through the code.
Public WithEvents olInspectors As Outlook.Inspectors Public WithEvents olMail As Outlook.MailItem Private Sub Initialize_handlers() Set olInspectors = Application.Inspectors End Sub Private Sub olInspectors_NewInspector(ByVal Inspector As Inspector) Dim olItem As Object Set olItem = Inspector.CurrentItem If TypeName(olItem) = "MailItem" Then Set olMail = olItem End Sub Private Sub olMail_AttachmentAdd(ByVal Attachment As Attachment) MsgBox "This is a test." If olMail.Subject = "" Then 'If you don't want the prompt, 'Just delete the Msgbox line and its corresponding "End if". If MsgBox("Do you want to use the attachment name as the subject", vbYesNo) = vbYes Then olMail.Subject = Attachment.DisplayName End If End If End Sub 推荐答案你的代码没有问题,你只需要初始化检查器
点击Sub Initialize_handlers()并按F5
Private Sub Initialize_handlers() Set olInspectors = Application.Inspectors End Sub或者只使用 Application.Startup Event (Outlook),保存并重新启动 Outlook,然后它应该可以工作了
Or just use Application.Startup Event (Outlook), Save it and restart Outlook then it should work
示例
Public WithEvents olInspectors As Outlook.Inspectors Public WithEvents olMail As Outlook.mailitem Private Sub Application_Startup() Set olInspectors = Application.Inspectors End Sub Private Sub Initialize_handlers() Set olInspectors = Application.Inspectors End Sub Private Sub olInspectors_NewInspector(ByVal Inspector As Inspector) Dim olItem As Object Set olItem = Inspector.CurrentItem If TypeName(olItem) = "MailItem" Then Set olMail = olItem End Sub Private Sub olMail_AttachmentAdd(ByVal Attachment As Attachment) MsgBox "This is a test." If olMail.Subject = "" Then 'If you don't want the prompt, 'Just delete the Msgbox line and its corresponding "End if". If MsgBox("Do you want to use the attachment name as the subject", _ vbYesNo) = vbYes Then olMail.Subject = Attachment.DisplayName End If End If End Sub更多推荐
如何初始化事件处理程序
发布评论