Solved

Changing Outlook Calendar Appointment Subject from VB Code

Posted on 2011-09-13
4
982 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
ID: 36551289
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
ID: 36553207
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
ID: 36554241
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
ID: 36554252
Here is the Color Categories dialog
Color-Categories.jpg
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you don't know how to downgrade, my instructions below should be helpful.
Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
In this video we show how to create an Accepted Domain 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 Mail Flow >> Ac…
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…

778 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