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
Solved

Update Outlook Appointment

Posted on 2004-08-20
1
555 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
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

839 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