troubleshooting Question

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

Avatar of pmpatane
pmpataneFlag for United States of America asked on
OutlookVBA
2 Comments1 Solution134 ViewsLast Modified:
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
ASKER CERTIFIED SOLUTION
Qlemo
"Batchelor", Developer and EE Topic Advisor
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros