Solved

Changing Outlook Calendar Appointment Subject from VB Code

Posted on 2011-09-13
4
978 Views
Last Modified: 2012-08-14
I have the following code:
    Dim app As New Outlook.Application
    Dim ns As NameSpace
    Dim Calendar As MAPIFolder
    Dim Item As Object
    Set ns = app.GetNamespace("MAPI")
    Set Calendar = ns.GetDefaultFolder(olFolderCalendar)
    For Each Item In Calendar.Items
        Item.Subject = "*" + Item.Subject
        DoEvents
    Next Item

From the Watch window I can see that it changes the item.subject field but it doesn't save it back to the appointment.  How do I get it to permanently update the Appointment's Subject?
0
Comment
Question by:cacomputerguy
  • 3
4 Comments
 
LVL 31

Accepted Solution

by:
Helen_Feddema earned 500 total points
Comment Utility
I would add a line to check the item type, and set a specific AppointmentItem variable in that case.  Then you have to close and save the modified item (no need for DoEvents).  Also, don't use reserved words like Calendar and Item as variable names, and use the ampersand instead of the plus sign for concatenaing.  Here is my modified code:
Public Sub UpdateAppts()

    Dim app As New Outlook.Application
    Dim ns As NameSpace
    Dim fldCalendar As MAPIFolder
    Dim itm As Object
    Dim appt As Outlook.AppointmentItem
    
    Set ns = app.GetNamespace("MAPI")
    Set fldCalendar = ns.GetDefaultFolder(olFolderCalendar)
    
    For Each itm In fldCalendar.Items
      If itm.Class = olAppointment Then
         Set appt = itm
         appt.Subject = "*" & appt.Subject
         appt.Close (olSave)
      End If
    Next itm

End Sub

Open in new window

0
 

Author Closing Comment

by:cacomputerguy
Comment Utility
Worked perfectly.  Is there some way to change the label color of the appointment as well as the subject?  Thanks very much.
0
 
LVL 31

Expert Comment

by:Helen_Feddema
Comment Utility
This depends on the version.  In Outlook 2007 and 2010, colors can be associated with categories, so all you need to do it set the category (field name:  Categories) to a specific value, and then the appointment label will have that color.  For earlier versions, I don't think this is possible.
0
 
LVL 31

Expert Comment

by:Helen_Feddema
Comment Utility
Here is the Color Categories dialog
Color-Categories.jpg
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Get an idea of what you should include in an email disclaimer with these Top 5 email disclaimer tips.
Sometimes Outlook might have problems sending a message. There may be various causes- corrupted PST, AV scanner etc. The message, instead of going to the Sent Items folder, sits in the Outbox indefinitely. To remove it you can use a free tool cal…
In this video we show how to create a Distribution Group in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >>…
To show how to generate a certificate request in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Servers >> Certificates…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now