Solved

Update Outlook Appointment

Posted on 2004-08-20
1
558 Views
Last Modified: 2013-12-25
Hi all

I am using the code below to search for all appointments after a certain date. Then I want to update the Categories of the appointments.

The problem is it adds a new appointment instead of Updating an existing one.
Any help highly appreciated.



 Dim objOutlook As Outlook.Application
        Dim objAppt As Outlook.AppointmentItem
        Dim objRecurPattern As Outlook.RecurrencePattern
  Set objOutlook = CreateObject("Outlook.Application")
        Set objAppt = objOutlook.CreateItem(olAppointmentItem)
       
 
 Dim ol As Object
      Dim olns As Object
      Dim objFolder As Object
      Dim objAllAppoint As Object
      Dim Appoint As Object
      ' Set the application object
      Set ol = New Outlook.Application
      ' Set the namespace object
      Set olns = ol.GetNamespace("MAPI")
      ' Set the default Calendar folder
      Set objFolder = olns.GetDefaultFolder(olFolderCalendar)
     
      Set objAllAppoint  = objFolder.Items
      ' Loop through each Appointment
     
      Dim st As String
      Dim dt As Date
      For Each Appoint  In objAllAppoint
     st = Format(Appoint.Start, "dd-mm-yyyy")
     dt = "01-01-2004"
     
         If st > dt Then
       
       
       objAppt.Categories = "Processed"
       
     
       objAppt.Save
     
  End if
Next
   

End Sub
0
Comment
Question by:Shezad Ahmed
[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
1 Comment
 
LVL 76

Accepted Solution

by:
David Lee earned 125 total points
ID: 11857538
Try this.  It works in my environment.

Private Sub Command1_Click()
    Dim objOutlook As New Outlook.Application
    Dim objNameSpace As Outlook.NameSpace
    Dim objFolder As Outlook.MAPIFolder
    Dim objAppt As Outlook.AppointmentItem
    Dim datStarting As Date
    Dim intCount As Integer
 
    ' Set the namespace object
    Set objNameSpace = objOutlook.GetNamespace("MAPI")
   
    ' Login to a profile
    objNameSpace.Logon "MyProfileName", "MyPassword"
   
    ' Set the default Calendar folder
    Set objFolder = objNameSpace.GetDefaultFolder(olFolderCalendar)
   
    ' Set the starting date (be sure to include a time too)
    datStarting = #8/19/2004 11:59:59 PM#
   
    ' Loop through the appointments backwards
    For intCount = objFolder.Items.Count To 1 Step -1
        ' Get the appointment item
        Set objAppt = objFolder.Items(intCount)
        ' Is the
        If objAppt.Start > datStarting Then
            ' Are other categories already present
            If Len(objAppt.Categories) > 0 Then
                ' Append the new category to the existing list of cats
                objAppt.Categories = objAppt.Categories & ",Processed"
            Else
                ' Set the category
                objAppt.Categories = "Processed"
            End If
            ' Save the appointment
            objAppt.Save
        End If
    Next
    ' Log out
    objNameSpace.Logoff
    ' Dispose of the objects to avoid memory leaks
    Set objAppt = Nothing
    Set objFolder = Nothing
    Set objNameSpace = Nothing
    Set objOutlook = Nothing
End Sub
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

729 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