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

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
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,224,820
Messages
6,181,162
Members
453,021
Latest member
Justyna P

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