Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove Outlook Appointments with VBA

Status
Not open for further replies.

PeDa

Technical User
Oct 10, 2002
227
NL
I am trying to remove Outlook appointments with a specific subject using VBA:

Code:
Set MyApp = CreateObject("Outlook.Application")
Set MyNS = MyApp.GetNamespace("MAPI")
Set MyFolder = MyNS.GetDefaultFolder(olFolderCalendar)
Set MyItems = MyFolder.Items
MyTotal = MyItems.Count
For i = 1 To MyTotal
  If (Left(MyItems.Item(i).Subject, 3) = "UA:") Then
    MyItems.Item(i).Delete
  End If
Next i

This generates the following error message half way through the removal process (tranlated from Dutch original):

Code:
Run-time error '-382599159 (e9320009)'
The limits of the matrix index have been exceeded

Any suggestions welcome.
 

When you delete items from a collection you generally need to work from the end backwards because deleting items changes the collection,

Try changing the loop control to
Code:
For i = MyTotal to 1 Step -1

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
Tony,

That did the trick. Many thanks; why didn't I think of that myself ;-((.

Peter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top