Can't get macro to run in Outlook 2010

Posted on 2010-08-18
Last Modified: 2012-06-27
I have this macro that used to run fine in Outlook 2007.
Now when I try to run it in 2010 I get mixed results.

Run in Visual Basic Editor: No problems, runs fine.
Run from Developer tab > Macros > Project: Nothing happens
Run from Developer Tab > Macros > Macros > Project > Run: "Sub or Function not defined." I can't see where in the code this is referring to.

I have digitally signed my macro.
My macro security is on: "Notifications for all macros".

Sub CancApt()

    Dim olkFld As Outlook.Folder, _

        olkLst As Outlook.Items, _

        olkItemsInDateRange As Outlook.Items, _

        olkApt As Outlook.AppointmentItem, _

        strRestriction As String, _

        intCnt As Integer, _

        intIdx As Integer, _

        intAnswer As String, _

        daStart As Date, _

        daEnd As Date


    'Enter a start and end date'

    daStart = InputBox("Enter a start date.", "Purge Canceled Appointments Start", (DateAdd("d", -7, Date)))

    daEnd = InputBox("Enter an end date.", "Purge Canceled Appointments End", (DateAdd("d", 60, Date)))



    'Construct a filter for the date range.

    strRestriction = "[Start] >= '" & daStart _

    & "' AND [End] <= '" & daEnd & "'"


    'Select calendar items in current folder

    intAnswer = MsgBox("Have you selected the calendar?", vbYesNo, "Wait")

    If intAnswer = vbYes Then


        GoTo EndMacro

    End If

    Set olkFld = Application.ActiveExplorer.CurrentFolder

    Set olkLst = olkFld.Items


    'To include recurring appointments, sort by using the Start property.

    olkLst.IncludeRecurrences = True

    olkLst.Sort "[Start]"


    'Restrict the Items collection.

    Set olkItemsInDateRange = olkLst.Restrict(strRestriction)

    'Loop to count the items'

    For Each olkApt In olkItemsInDateRange

        intCnt = intCnt + 1


    'Loop to process the items'

    For intIdx = intCnt To 1 Step -1

        Set olkApt = olkItemsInDateRange(intIdx)

        If Left(olkApt.Subject, 9) = "Canceled:" Then


        End If




    Set olkFld = Nothing

    Set olkLst = Nothing

    Set olkApt = Nothing

    MsgBox "Purge complete.", vbInformation + vbOKOnly, "Purge Canceled Appointments"

End Sub

Open in new window

Question by:Relentim
  • 2
LVL 59

Accepted Solution

Chris Bottomley earned 500 total points
Comment Utility
WHere have you placed the code, a normal module or in thisoutlooksession


Author Comment

Comment Utility
It was in a normal module.
I've now put it in thisoutlooksession and it works.


Author Closing Comment

Comment Utility
It was in a normal module.
I've now put it in thisoutlooksession and it works.

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Set OWA language and time zone in Exchange for individuals, all users or per database.
Sometimes Outlook might have problems sending a message. There may be various causes- corrupted PST, AV scanner etc. The message, instead of going to the Sent Items folder, sits in the Outbox indefinitely. To remove it you can use a free tool cal…
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now