Outlook macros that have worked for a long time suddenly erroring out

pmpatane
pmpatane used Ask the Experts™
on
I have some Outlook VBA code that has worked fine for quite a while but has recently been erroring out.  I do not know what has changed in VBA rules that causes the problem.  The statement Dim olkIS As Outlook.Store seems to be the problem.  The variable olkIS always seems to cause the error.  I have attached 2 different codes.  They both error out at the Next statement, as if no olkIS  are found.  Is there a problem with my Dim statement?  When I debug I get Run-time error '-1075576559 (bfe40111)':



Sub OOO7Project()

    Const PR_OOF_STATE = "http://schemas.microsoft.com/mapi/proptag/0x661D000B"
    Dim olkIS As Outlook.Store
    Dim olkPA As Outlook.PropertyAccessor
    Dim olkOOFMessage As Outlook.StorageItem
    Dim Text1, Text2, Text3, TextComma As String
    
    TextComma = ", "
    Text1 = "Thanks for your e-mail! "
    Text2 = "I am currently working on a special project today, "
    Text3 = ", and may not be able to return calls or email for a few hours.   If this is an urgent matter, please call 111 or email TECHSUPPORTTEAM. "

    For Each olkIS In Session.Stores
        If olkIS.ExchangeStoreType = olPrimaryExchangeMailbox Then
            Set olkPA = olkIS.PropertyAccessor
            olkPA.SetProperty PR_OOF_STATE, True
            Set olkOOFMessage = Outlook.Session.GetDefaultFolder(olFolderInbox).GetStorage("IPM.Note.Rules.OofTemplate.Microsoft", olIdentifyByMessageClass)
            olkOOFMessage.Body = Text1 & Chr$(13) & Chr$(13) & Text2 & WeekdayName(Weekday(Date)) & TextComma & Date & Text3
            olkOOFMessage.Save
            Exit For
        End If
    Next
    Set olkIS = Nothing
    Set olkPA = Nothing
    Set olkOOFMessage = Nothing

End Sub



Sub OOO7TwoDays()

    Const PR_OOF_STATE = "http://schemas.microsoft.com/mapi/proptag/0x661D000B"
    Dim olkIS As Outlook.Store
    Dim olkPA As Outlook.PropertyAccessor
    Dim olkOOFMessage As Outlook.StorageItem
    Dim Text1, Text2, Text3, TextComma, TextDash As String
    
    TextComma = ", "
    TextDash = " - "
    Text1 = "Thanks for your e-mail! "
    Text2 = "I am out of the office beginning "
    Text3 = " and will be returning "
    Text4 = ".   If this is an urgent matter, please call 111 or email TECHSUPPORTTEAM. "

    StartDate = InputBox("What is the 1st day out?", "OOO Setting")
    EndDate = InputBox("What day are you returning?", "OOO Setting")

    For Each olkIS In Session.Stores
        If olkIS.ExchangeStoreType = olPrimaryExchangeMailbox Then
            Set olkPA = olkIS.PropertyAccessor
            olkPA.SetProperty PR_OOF_STATE, True
            Set olkOOFMessage = Outlook.Session.GetDefaultFolder(olFolderInbox).GetStorage("IPM.Note.Rules.OofTemplate.Microsoft", olIdentifyByMessageClass)
            olkOOFMessage.Body = Text1 & Chr$(13) & Chr$(13) & Text2 & WeekdayName(Weekday(StartDate)) & TextComma & StartDate & TextComma & Text3 & WeekdayName(Weekday(EndDate)) & TextComma & EndDate & Text4
            olkOOFMessage.Save
            Exit For
        End If
    Next
    Set olkIS = Nothing
    Set olkPA = Nothing
    Set olkOOFMessage = Nothing

End Sub

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
"Batchelor", Developer and EE Topic Advisor
Top Expert 2015
Commented:
How about setting a debug breakpoint on tthe IF inside the loop, and watch the objects it is going through? You might see a somehow different Store object not exposing ExchangeStoreType, for example. If that is the case, you need the On Error Resume Next to ignore errors.

Author

Commented:
Thanks, resuming the code was what helped.  There is another issue, but I will address that in a separate question.  Thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial