We help IT Professionals succeed at work.

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

pmpatane
pmpatane asked
on
124 Views
Last Modified: 2019-01-11
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

"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

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

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.