如何初始化事件处理程序

编程入门 行业动态 更新时间:2024-10-26 23:25:09
本文介绍了如何初始化事件处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在在线.它应该使用我提供的任何附件自动填充我的主题行.代码不运行.

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

更多推荐

如何初始化事件处理程序

本文发布于:2023-11-04 01:24:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1556565.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:初始化   事件   程序

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!