Solved

Changing Outlook Calendar Appointment Subject from VB Code

Posted on 2011-09-13
4
990 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
The new Gmail Phishing Scam going around is surprising even the savviest of users with its sophisticated techniques.
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

763 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