我已经用Outlook的Visual Basic (我们使用的是Outlook 2003和Exchange Server)编写了一个邮件处理函数来帮助我对传入的电子邮件进行分类。
它对我来说是有效的,除了有时规则失败和Outlook停用它。
然后,我重新打开规则,并在我的收件箱中手动运行它,以跟上进度。该规则会自动失效并在一天内停用几次。
我很乐意一劳永逸地解决这个问题。
发布于 2011-12-30 03:03:09
这段代码向我展示了收件箱中的不同TypeNames:
Public Sub GetTypeNamesInbox()
Dim myOlItems As Outlook.Items
Set myOlItems = application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
Dim msg As Object
For Each msg In myOlItems
Debug.Print TypeName(msg)
'emails are typename MailItem
'Meeting responses are typename MeetingItem
'Delivery receipts are typename ReportItem
Next msg
End SubHTH
发布于 2008-09-17 01:39:17
我用Outlook的Visual Basic (我们使用的是Outlook 2003和Exchange Server)编写了一个邮件处理函数来帮助我整理收到的电子邮件。它对我来说是有效的,除了有时规则失败和Outlook停用它。然后,我重新打开规则,并在我的收件箱中手动运行它,以跟上进度。该规则会自动失效并在一天内停用几次。我很乐意一劳永逸地解决这个问题。
下面是从功能中剥离出来的代码,但让您对它的外观有一个概念:
Public WithEvents myOlItems As Outlook.Items
Public Sub Application_Startup()
' Reference the items in the Inbox. Because myOlItems is declared
' "WithEvents" the ItemAdd event will fire below.
' Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items
Set myOlItems = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub myOlItems_ItemAdd(ByVal Item As Object)
On Error Resume Next
If TypeName(Item) = "MailItem" Then
MyMessageHandler Item
End If
End Sub
Public Sub MyMessageHandler(ByRef Item As MailItem)
Dim strSender As String
Dim strSubject As String
If TypeName(Item) <> "MailItem" Then
Exit Sub
End If
strSender = LCase(Item.SenderEmailAddress)
strSubject = Item.Subject
rem do stuff
rem do stuff
rem do stuff
End Sub我得到的一个错误是“类型不匹配”调用MyMessageHandler,其中VB抱怨项目不是MailItem。好的,但是TypeName( Item )返回" MailItem ",那么为什么Item不是MailItem呢?
我收到的另一个问题是一封主题为空的电子邮件。这条线
strSubject = Item.Subject给了我一个错误。我知道Item.Subject应该是空的,但是为什么这是一个错误?
谢谢。
发布于 2012-08-30 02:10:35
我在直接引用Outlook库的其他Office应用程序中使用以下VBA代码片段。
' Outlook Variables
Dim objOutlook As Outlook.Application: Set objOutlook = New Outlook.Application
Dim objNameSpace As Outlook.NameSpace: Set objNameSpace = objOutlook.GetNamespace("MAPI")
Dim objFolder As MAPIFolder: Set objFolder = objNameSpace.PickFolder()
Dim objMailItem As Outlook.MailItem
Dim iCounter As Integer: iCounter = objFolder.Items.Count
Dim i As Integer
For i = iCounter To 1 Step -1
If TypeOf objFolder.Items(i) Is MailItem Then
Set objMailItem = objFolder.Items(i)
With objMailItem等。
https://stackoverflow.com/questions/78924
复制相似问题