使用 VBA 阅读新的 Outlook 电子邮件?

编程入门 行业动态 更新时间:2024-10-28 16:20:59
本文介绍了使用 VBA 阅读新的 Outlook 电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有以下代码告诉新消息何时到达!

I have the following code which tells when new message has arrived!

Private Sub Application_NewMail() MsgBox "New Mail Has Arrived" End Sub

我如何阅读这封邮件的正文和主题?有没有好的outlook编程教程?

How do I read the body,subject of this mail? Are there any good tutorials for outlook programming?

我发现 msdn 教程很有用,但是概述.

I found msdn tutorial which was useful but was general overview.

推荐答案

你需要这样的东西:

Private WithEvents myOlItems As Outlook.Items Private Sub Application_Startup() Dim olApp As Outlook.Application Dim objNS As Outlook.NameSpace Set olApp = Outlook.Application Set objNS = olApp.GetNamespace("MAPI") Set myOlItems = objNS.GetDefaultFolder(olFolderInbox).Items End Sub Private Sub myOlItems_ItemAdd(ByVal item As Object) On Error GoTo ErrorHandler Dim Msg As Outlook.MailItem If TypeName(item) = "MailItem" Then Set Msg = item MsgBox Msg.Subject MsgBox Msg.Body End If ProgramExit: Exit Sub ErrorHandler: MsgBox Err.Number & " - " & Err.Description Resume ProgramExit End Sub

将代码粘贴到 ThisOutlookSession 并重新启动 Outlook.当邮件进入您的默认本地收件箱时,您会看到带有主题和正文的弹出窗口.

Paste the code into ThisOutlookSession and restart Outlook. When a message enters your default local Inbox you'll see the popup with subject and body.

更多推荐

使用 VBA 阅读新的 Outlook 电子邮件?

本文发布于:2023-06-08 23:39:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/591056.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:电子邮件   VBA   Outlook

发布评论

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

>www.elefans.com

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