Deleting appointments outlook via VBA Excel

Ronaldjm

New Member
Joined
Jan 9, 2019
Messages
1
Hi,

Se code below text.
As I am running below mentioned script it is deleting every time approxm half the appointments
So 1st time running example 100 appointments.
second time running script 50 appointments deleted
third time 15 etc etc

So it looks as I am skipping one extra appointment for deleting...

Please advice :)


For Each objAppointment In objFolder.Items
If objAppointment.Categories = "test vba" Then
objAppointment.Delete
lngDeletedAppointements = lngDeletedAppointements + 1

End If
Next
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi Ronaldjm,

When deleting records it always advisable to do it in reverse order. start at last and end with the first.

Try something like

[FONT=&quot]You will need to use a down loop[/FONT]
[FONT=&quot]for i = Items.Count to 1 step -1[/FONT]
[FONT=&quot] Items(i).Delete[/FONT]
[FONT=&quot]next[/FONT]
 
Upvote 0
Try deleting them in reverse order:
Code:
    Dim i As Long
    For i = objFolder.Items.Count To 1 Step -1
        Set objAppointment = objFolder.Items(i)
        If objAppointment.Categories = "test vba" Then
            objAppointment.Delete
            lngDeletedAppointments = lngDeletedAppointments + 1
        End If
    Next
 
Upvote 0

Forum statistics

Threads
1,222,749
Messages
6,167,958
Members
452,158
Latest member
MattyM

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top