我们之前运行的是 Outlook 2007,我创建了一个脚本,用于对具有设置参考模式的电子邮件与没有设置参考模式的电子邮件进行排序。但是,由于更改为 Outlook 2013,该脚本不再有效。有效的脚本如下:
Const olFolderInbox = 6
Set objOutlook = CreateObject("Outlook.Application") 'creates outlook application
Set objNamespace = objOutlook.GetNamespace("MAPI") 'sets the name space
Set objInbox = objNamespace.GetDefaultFolder(olFolderInbox) 'finds the inbox
strFolderName = objInbox.Parent
Set objMailbox = objNamespace.Folders(strFolderName) 'sets the mailbox
Set objUnprocessed = objMailbox.Folders("Unprocessed Incoming Emails") 'sets one of the folders needed
Set objForwardFolder = objMailbox.Folders("Forwarded Emails") 'sets other folder needed
set objRegex = CreateObject("VBScript.RegExp") 'creates regex object
With objRegex
.Pattern = "^([a-z?-i]{1}([0-9]{3})([0-9]?)|[1][0][1-9]{2})$" 'first regex pattern to check
.Global = True
end With
set objReg = CreateObject("VBScript.RegExp") 'creates second regex object
With objReg
.Pattern = "([a-z?-i]{1}([0-9]{3})([0-9]?)|[1][0][1-9]{2})" 'second regex to check
.Global = True
end With
set objRegSlash = CreateObject("VBScript.RegExp") 'creates third regex object
With objRegSlash
.Pattern = "[\/]" 'used to change forwardslashes with spaces
.Global = True
end With
lngCount = objUnprocessed.Items.Count 'returns the count of the items in the Unprocessed Emails Folder
For j = lngCount To 1 Step - 1 'for every item do the following
matchingRef = "" 'used to return the reference in the email if matches
EmailCheckString = objUnprocessed.Items(j) 'returns the email subject line
if objReg.test(EmailCheckString) then 'if the subject line matches the first regex
set EmailCheckString = objUnprocessed.Items(j) 'sets the subject line again
if objRegSlash.test(EmailCheckString) then 'if the subject line contains forward slashes
EmailCheckString = Replace(EmailCheckString, "/", " ") 'replace with space
end if
EmailCheckString = Split(EmailCheckString, " ") 'splits the subject line into an array as of each word
for each word in EmailCheckString 'for each word in the array
if objRegex.test(word) then 'if word matches secondary regex
matchingRef = word 'matching ref is returns
exit for 'exit loop
end if
Next
if matchingRef <> "" then 'if the matching ref has been set
Set nameChange = objUnprocessed.Items(j)
nameChange.Subject = matchingRef 'changes the subject line to the reference
nameChange.Save 'saves item
objUnprocessed.Items(j).Move objInbox 'moves to the inbox
else
set autoForward = objUnprocessed.Items(j).Forward 'sets the email to forward
autoForward.Recipients.Add "name@domain.co.uk" 'adds email address
autoForward.Send 'sends
if objUnprocessed.Items(j).UnRead then 'if item is unread
objUnprocessed.Items(j).UnRead = false 'set to read
objUnprocessed.Items(j).Move objForwardFolder 'move to forwarded emails folder
else
objUnprocessed.Items(j).Move objForwardFolder 'move to forwarded emails folder
end if
end if
else
set autoForward = objUnprocessed.Items(j).Forward 'sets email to forward
autoForward.Recipients.Add "name@domain.co.uk" 'adds email address
autoForward.Send 'sends
if objUnprocessed.Items(j).UnRead then 'if the item is unread
objUnprocessed.Items(j).UnRead = false 'set to read
objUnprocessed.Items(j).Move objForwardFolder 'move to forwarded emails folder
else
objUnprocessed.Items(j).Move objForwardFolder 'move to forwarded emails folder
end if
end if
next
但是它现在在第一个 EmailCheckString = objUnprocessed.Items(j) 处中断并显示:错误:对象不支持此属性或方法:'EmailCheckString' 代码:800A01B6
在升级 Outlook 2013 之前,此脚本运行良好。对于如何解决这个问题,有任何的建议吗?