Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Changing Outlook Calendar Appointment Subject from VB Code

Posted on 2011-09-13
4
Medium Priority
?
1,007 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
Changing a few Outlook Options can help keep you organized!
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

636 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