?
Solved

Changing Outlook Calendar Appointment Subject from VB Code

Posted on 2011-09-13
4
Medium Priority
?
999 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When you have clients or friends from around the world, it becomes a challenge to arrange a meeting or effectively manage your time. This is where Outlook's capability to show 2 time zones in one calendar comes in handy.
As cyber crime continues to grow in both numbers and sophistication, a troubling trend of optimization has emerged over the last year.
In this video we show how to create a mailbox database 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 >> Data…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…
Suggested Courses

777 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