• VBA to Delete All Recurring appts in span(2003)

    Home » Forums » AskWoody support » Productivity software by function » MS Outlook and email programs » VBA to Delete All Recurring appts in span(2003)

    Author
    Topic
    #423745

    When deleting recurring events, Outlook prompts the user if he/she wants to delete the whole series or just the occurrence. if you select, just the occurrence then only that particular event will be deleted else the whole series gets deleted.

    Hope that helps,
    Regards,
    Bikash.

    Viewing 1 reply thread
    Author
    Replies
    • #970928

      Thanks. But waht i want to do is if for example I go on vacation for a week (I wish) to remove all appointments for that week or a specific day, without having to do it one by one, but without removing the recurring appointment completely.

      • #970935

        AS far as I know, there is no way to do it using the Outlook User Interface. Through code, you probably could.

        Hope that helps,
        Regards,
        Bikash.

    • #970886

      If you have recurring appointments, i.e. classes for the whole school year, and you want to clear all the appointments for a certain day or week, without erasing te whole recurrence. How do you do that?
      thanks

      • #970969

        (Edited by HansV to make URL clickable – see Help 19)

        Based on code found at http://www.outlookcode.com/codedetail.aspx?id=165%5B/url%5D I changed the following to delete all recurring appointments in a given span. Any improvements would be greatly appreciated

        Zave

        Function DateSpan(colItems As Outlook.Items, _
                dteStart As Date, dteEnd As Date) _
                As Outlook.Items
            Dim colSpanItems As Outlook.Items
            On Error Resume Next
            colItems.Sort "[Start]"
            colItems.IncludeRecurrences = True
            strFind = "[Start]  " & _
                Quote(Format(dteStart, "ddddd") & " 12:00 AM")
            'MsgBox strFind
            Set colSpanItems = colItems.Restrict(strFind)
            If Err = 0 Then
                Set DateSpan = colSpanItems
            End If
            Set colSpanItems = Nothing
        End Function
         
        Function Quote(MyText)
            Quote = Chr(34) & MyText & Chr(34)
        End Function
         
        Sub TestDateSpan()
            Dim objOL As Outlook.Application
            Dim objNS As Outlook.NameSpace
            Dim colCal As Outlook.Items
            Dim objAppt As Outlook.AppointmentItem
            Dim dtStart As Date
            Dim dtEnd As Date
            On Error Resume Next
         
            dtStart = InputBox("Enter Start Date as date mm/dd/yyyy", "Start date")
            dtStart = "#" & Format(dtStart, "mm/dd/yyyy") & "#"
            dtEnd = InputBox("Enter End Date as date mm/dd/yyyy", "End Date")
            dtEnd = "#" & Format(dtEnd, "mm/dd/yyyy") & "#"
         
            Set objOL = CreateObject("Outlook.Application")
            Set objNS = objOL.GetNamespace("MAPI")
            Set colCal = objNS.GetDefaultFolder(olFolderCalendar).Items
            Set colSpanItems = DateSpan(colCal, dtStart, dtEnd)
            For Each objAppt In colSpanItems
                ' Debug.Print objAppt.Subject, objAppt.Start, objAppt.End, objAppt.RecurrenceState
                If objAppt.RecurrenceState = olApptOccurrence Then
                    objAppt.Delete
                End If
            Next
            Set objAppt = Nothing
            Set colSpanItems = Nothing
            Set colCal = Nothing
        End Sub
    Viewing 1 reply thread
    Reply To: Reply #970969 in VBA to Delete All Recurring appts in span(2003)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel