Обновление до Outlook 2013 убило VBScript

Ранее мы использовали 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 "[email protected]" '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 "[email protected]" '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. Любые предложения о том, как это исправить?


person NItroGhost    schedule 23.06.2014    source источник


Ответы (1)


Вам не хватает "набора":

set EmailCheckString = objUnprocessed.Items(j)

Или, внимательно изучив свой код, вы ожидали получить строковое свойство по умолчанию, которое оказалось Subject). Попробуйте явно запросить его:

EmailCheckString = objUnprocessed.Items(j).Subject
person Dmitry Streblechenko    schedule 23.06.2014