Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Can't get macro to run in Outlook 2010

Posted on 2010-08-18
3
Medium Priority
?
868 Views
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
    Else
        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
    Next
    'Loop to process the items'
    For intIdx = intCnt To 1 Step -1
        Set olkApt = olkItemsInDateRange(intIdx)
        If Left(olkApt.Subject, 9) = "Canceled:" Then
            olkApt.Delete
        End If
    Next
    
EndMacro:
    Set olkFld = Nothing
    Set olkLst = Nothing
    Set olkApt = Nothing
    MsgBox "Purge complete.", vbInformation + vbOKOnly, "Purge Canceled Appointments"
End Sub

Open in new window

0
Comment
Question by:Relentim
  • 2
3 Comments
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 2000 total points
ID: 33463155
WHere have you placed the code, a normal module or in thisoutlooksession

Chris
0
 
LVL 1

Author Comment

by:Relentim
ID: 33463191
Oh!
It was in a normal module.
I've now put it in thisoutlooksession and it works.

Thanks.
0
 
LVL 1

Author Closing Comment

by:Relentim
ID: 33463192
It was in a normal module.
I've now put it in thisoutlooksession and it works.
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Lost Word File? Eagerly, need it back? Read ahead; this File Recovery guide is for you.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

971 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