Link to home
Start Free TrialLog in
Avatar of pmpatane
pmpataneFlag 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

ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pmpatane

ASKER

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