Avatar of pmpatane
pmpatane
Flag for United States of America asked on

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

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

OutlookVBA

Avatar of undefined
Last Comment
pmpatane

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Qlemo

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
pmpatane

ASKER
Thanks, resuming the code was what helped.  There is another issue, but I will address that in a separate question.  Thanks!
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes