问题描述
我正在为Outlook 2010的VBA宏工作,以将传入的电子邮件过滤和分类到不同的文件夹中.目标中提到了规则当涉及到实施和测试时,它会提示错误消息框,而不是成功进行过滤.您能告诉我默认调用Application_NewMail
下的哪一部分继续进行吗?
I am working for the VBA Macros of Outlook 2010 to filter and categorize incoming emails into different folders. The rule is mentioned in the target When it comes to the implementation and testing, it does prompting error messages boxes instead of successful filtering. Would you please tell me what section under default call Application_NewMail
shall proceed ?
目标:
在[此括号]中提取单词
extract words within [this Bracket]
主题:[CMX]
->创建收件箱文件夹ABC
Subject : [CMX]
--> create inbox folder ABC
主题:CMX
->创建收件箱文件夹CMX
Subject : CMX
--> create inbox folder CMX
主题:INC000000156156
->创建收件箱文件夹INC
和子文件夹INC000000156156
Subject : INC000000156156
--> create inbox folder INC
and sub-folder INC000000156156
编程语言:VBA宏
Outlook版本:2010
Outlook Version : 2010
这是我的代码,我不知道如何创建文件夹(如果为空)并将电子邮件分配给该文件夹:
Here is my code and I have no clue on how to create folders if empty and assign email to the folder :
Private Sub Application_NewMail()
Dim olFld As Outlook.MAPIFolder
Set olFld = Outlook.Session.GetDefaultFolder(olFolderInbox)
olFld.Items.Sort "[ReceivedTime]", False
Dim olMail As Outlook.MailItem
Set olMail = olFld.Items.GetFirst
MyNiftyFilter olMail
End Sub
Private Sub MyNiftyFilter(Item As Outlook.MailItem)
Debug.Print Item
Debug.Print Item.Subject
Dim Matches As Variant
Dim RegExp As New VBScript_RegExp_55.RegExp
Dim Pattern As String
Dim Email_Subject As String
Pattern = "(([\w-\s]*)\s*)"
Email_Subject = Item.Subject
With RegExp
.Global = False
.Pattern = Pattern
.IgnoreCase = True
Set Matches = .Execute(Email_Subject)
End With
If Matches.Count > 0 Then
End If
Set RegExp = Nothing
Set Matches = Nothing
Set Item = Nothing
End Sub
推荐答案
您可以使用ItemAdd event
https://stackoverflow.com/a/58428753/4539709 或将您的NewMail
修复为简单的
You either use ItemAdd event
https://stackoverflow.com/a/58428753/4539709 or fix your NewMail
to simply
Private Sub Application_NewMail()
Dim Item As Outlook.MailItem
MyNiftyFilter Item
End Sub
这篇关于正则表达式引起的传入分类:Application_NewMail:字节Val不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!