我正在尝试为Outlook 2010创建一个自定义规则,检查电子邮件主题并将其移动到特定文件夹中,但是当我运行脚本时,获取要移动邮件的文件夹的Outlook.Folder对象时,出现以下错误:
“Run-time error '91':
Object variable or With block variable not set”
下面是我使用的VBA脚本,用于检查电子邮件主题并将消息移动到指定的文件夹(如果匹配)。
“Run-time error '91':
Object variable or With block variable not set”
下面是我使用的VBA脚本,用于检查电子邮件主题并将消息移动到指定的文件夹(如果匹配)。
Sub MoveToETS(Item As Outlook.MailItem)
Dim Subject As String
Subject = Item.Subject
Dim FolderToMoveTo As Outlook.Folder
Set FolderToMoveTo = GetFolder("ETS")
If (CheckSubject(Subject, "^[Project|Bug] (\d+?) - \[[UPDATE|NEW|RESOLVED]\]")) Then
Item.Move (FolderToMoveTo)
End If
End Sub
Function CheckSubject(Subject As String, PatternToCheck As String)
Dim ObjRegExp As RegExp
Dim ObjMatch As Match
Set ObjRegExp = New RegExp
ObjRegExp.Pattern = PatternToCheck
If (ObjRegExp.Text(Subject) = True) Then
CheckSubject = True
End If
End Function
Function GetFolder(ByVal FolderName As String) As Outlook.Folder
Dim ObjFolder As Outlook.Folder
Set ObjFolder = Outlook.Application.Session.GetDefaultFolder(olFolderInbox).Folders("ETS")
GetFolder = ObjFolder
End Function