Monday, December 07, 2009

Remove "Copy: " from Outlook Calendar Items

Recently I changed over to a new company (sort of, long story) and had to import all my calendar items onto the new Exchange server. Actually, I wanted all my email, tasks, and everything to move, so I exported my entire mailbox as a PST and then opened it while connected to the new server and moved everything from the PST onto the server. It was all fine until I noticed all my calender items all now begin with "Copy: " Most annoying. So I wrote a VBA script to take the word "Copy: " out of the beginning of all my appointments. Actually, the concepts behind the script are useful anytime you'd want to loop through a list of Outlook items. Here's the script:

Sub deleteCopyText()
Dim counter As Integer
Dim objOL As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim colCal As Outlook.Items
Dim objAppt As Outlook.AppointmentItem
Set objOL = CreateObject("Outlook.Application")
Set objNS = objOL.GetNamespace("MAPI")
Set colCal = objNS.GetDefaultFolder(olFolderCalendar).Items
counter = 0
For Each objAppt In colCal
If Left(objAppt.Subject, 6) = "Copy: " Then
'MsgBox objAppt.Subject
objAppt.Subject = Replace(objAppt.Subject, "Copy: ", "")
'MsgBox objAppt.Subject
objAppt.Save
counter = counter + 1
End If
Next
MsgBox "Complete. " & counter & " items renamed."

End Sub

This script will ignore anything that does not begin with "Copy: ". You can uncomment out the msgbox lines if you want to see what change it is going to make one by one. To run it, open Outlook. Pres alt+F11 - this will get you into the VBA environment. Right click Project1 in the Project window and select "Insert -> New Module" Paste the code above (from sub deleteCopyText() to end sub()). Press F5 to run the script or if you want to be cautious, press F8 and it will run it one line at a time (press F8 repeatedly until you are satisfied it is doing what you think it should, then press F5 to run the script without stopping). You probably won't want to run the script with the msgbox lines uncommented if you have lots of calendar items, otherwise it will pop up two message boxes that you have to clear for each calendar item it is going to change. If that happens to you, press Ctrl+Break to stop the script. You could also comment out objAppt.Save if you just wanted to run the script to see how many calendar items it is going to change (no changes will actually be made).

2 Comments:

Anonymous Anonymous said...

Thanks, this was extremely helpful and the only thing I've found on the net that could help with this.

January 4, 2010 1:00 PM  
Anonymous Anonymous said...

Incredible - great job! I couldn't find anything on the web to fix the Copy before each calendar entry and then I found your post - 1325 entries later - all fixed!

Thank You

February 8, 2010 6:16 AM  

Post a Comment

<< Home