Loop on all appointments

M

Markus Pesti

I would like to modify the subject-string of all appointments saved in
Outlook-calendar. Especially I want to remove specific characters from
these subjects. Can anyone help me how to formulate the loop for doing this?

Markus
 
G

Guest

Try this macro:

Sub LoopThroughAppointments()
On Error Resume Next

Dim objNS As Outlook.NameSpace
Dim objCalendar As Outlook.MAPIFolder
Dim objApptItem As Outlook.AppointmentItem

Set objNS = Application.GetNamespace("MAPI")
Set objCalendar = objNS.GetDefaultFolder(olFolderCalendar)

For Each objApptItem In objCalendar.Items
Debug.Print objApptItem.Subject

'Replace characters in Subject line
If InStr(objApptItem.Subject, "characters to find") > 0 Then
objApptItem.Subject = Replace(objApptItem.Subject, "characters
to find", "replacement characters")
objApptItem.Save
End If
Next

Set objNS = Nothing
Set objCalendar = Nothing
Set objApptItem = Nothing
End Sub
 
M

Markus Pesti

Eric said:
Try this macro:

Sub LoopThroughAppointments()
On Error Resume Next

Dim objNS As Outlook.NameSpace
Dim objCalendar As Outlook.MAPIFolder
Dim objApptItem As Outlook.AppointmentItem

Set objNS = Application.GetNamespace("MAPI")
Set objCalendar = objNS.GetDefaultFolder(olFolderCalendar)

For Each objApptItem In objCalendar.Items
Debug.Print objApptItem.Subject

'Replace characters in Subject line
If InStr(objApptItem.Subject, "characters to find") > 0 Then
objApptItem.Subject = Replace(objApptItem.Subject, "characters
to find", "replacement characters")
objApptItem.Save
End If
Next

Set objNS = Nothing
Set objCalendar = Nothing
Set objApptItem = Nothing
End Sub

Sounds fine, but will it also work if 'objApptItem.Subject' is an
unicode string?

Markus
 
G

Guest

AFAIK, a string is a string, and the InStr and Replace functions will work
for textual comparisons if you specify vbTextCompare as the argument,
regardless of the language used.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top