Solved

Update Outlook Appointment

Posted on 2004-08-20
1
552 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now