Calendar entries with duplicate names

  • Thread starter Thread starter Dieter Molle
  • Start date Start date
D

Dieter Molle

Hi all,

maybe someone can help me:

i try to edit calendar entries with a VB Script like this:

'---------------------------
Const olFolderCalendar = 9

Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNameSpace("MAPI")

Set myOLFolder = myNameSpace.GetDefaultFolder(olFolderCalendar)
Set myEntry = myOLFolder.items("Test 1234")
myEntry.Body = "Hello :-)"
myEntry.save
'---------------------------

As you can see, i want to reference the item by its subject. The
script runs fine.

Now my problem is: what if i have two or more calendar items with the
same subject?! This script writes to the first item found.
Can i loop through all items with a special subject?
What i could do was loop throug ALL calendar items and looking for
those where the subject matches, but is there no easier way to do
this?

Thanks in advance for your help,
Greetings,
Dieter
 
What you can do is set up a filter or restriction on the Items collection of
that folder. A filter can be set up and then you can iterate the Items
collection using FindFirst and FindNext until FindNext returns a null
object. Or with a restriction you get a filtered Items collection that can
just be iterated.

For example:

Const olFolderCalendar = 9

Set myOlApp = CreateObject("Outlook.Application")
'if run in an Outlook form use Application instead like this:
'Set myNameSpace = Application.GetNameSpace("MAPI")
'no need to create an Outlook Application object

Set myNameSpace = myOlApp.GetNameSpace("MAPI")

Set myOLFolder = myNameSpace.GetDefaultFolder(olFolderCalendar)
strRestrict = "[Subject] = " & """Test 1234"""
Set myItems = myOLFolder.items.Restrict(strRestrict)
For Each myEntry In myItems
myEntry.Body = "Hello :-)"
myEntry.save
Next
 
Back
Top