There is a good amount of information on the web about this and I read a lot of it. I have taken my code from this link and tried it in VBScript and Visual Basic:
However, I am not able to get it to run properly. I get the following error:
The error I get is:
Microsoft VBScript runtime error: ActiveX component can't create object: 'CDO.ICalendarPart'
When trying to instantiate this object. I've tried CDOEX and other varations.
I have the ESM tools insalled on my machine and am running the code in a privileged account. I have copied the cdoex.dll from an Exchange server to my workstation and registered it. I have also run the code on the exchange server where the mailbox resides - same error. I guess it is not a CDO object. I've actually tried a number of things and generated a fun assortment of errors.
Since the code from the website is provided in Visual Basic, I tried that. No matter what references I add in Visual Studio, it does not recognize the CalendarMessage, ICalendarPart, CdoDAV.cdoHref, etc. I read something about the CDOEX being available via CDO through an interop and I tried some things in that area, but no success as yet. I'm hitting my ceiling in terms of expertise, so I need help.
Here is the code, where <MyUserName>, <server> and <my primary SMTP address> are replaced with actual values. I'm not using the M drive as you can see.
Code: Select all
Dim InboxURL ' As String Dim CalendarURL ' As String Dim ItemURL ' As String Dim Rs Set Rs = CreateObject("ADODB.Recordset") Dim Rec Set Rec = CreateObject("ADODB.Record") Dim iCalMsg Set iCalMsg = CreateObject("CDO.CalendarMessage") Dim iCalPart ' As ICalendarPart Set iCalPart = CreateObject("CDO.ICalendarPart") Dim iAppt Set iAppt = CreateObject("CDO.Appointment") Dim Index ' As Integer Dim ContentClass ' As String Dim Config Set Config = CreateObject("CDO.Configuration") InboxURL = "/Exchange/<MyUserName>/Inbox">http://<server>/Exchange/<MyUserName>/Inbox" CalendarURL = "/Exchange/<MyUserName>/Calendar">http://<server>/Exchange/<MyUserName>/Calendar" 'Set the configuration fields for the appointment objects Config.Fields("cdoSendEmailAddress") = "<my primary SMTP address>" Config.Fields("CalendarLocation") = CalendarURL Config.Fields.Update 'Open a recordset for the items in the inbox folder Rec.Open InboxURL Set Rs.ActiveConnection = Rec.ActiveConnection Rs.Source = "select ""DAV:href"",""DAV:contentclass"" from scope('shallow traversal of """ & InboxURL & """')" Rs.Open 'Enumerate the recordset, checking each item's content class Rs.MoveFirst Do Until Rs.EOF 'get the content class of each item ContentClass = Rs.Fields("DAV:contentclass").Value 'test content class for calendar message If ContentClass = "urn:content-classes:calendarmessage" Then 'open calendar message ItemURL = Rs.Fields(CdoDAV.cdoHref).Value iCalMsg.DataSource.Open ItemURL iCalMsg.Configuration = Config Debug.Print "Message subject: " & iCalMsg.Message.Subject 'get each calendar part For Index = 1 To iCalMsg.CalendarParts.Count Set iCalPart = iCalMsg.CalendarParts(Index) Set iAppt = iCalPart.GetUpdatedItem Select Case iCalPart.CalendarMethod Case "CANCEL" 'Save the appointment ' iAppt.DataSource.Save Wscript.Echo iAppt.DataSource.Save Case Else 'see other examples in this section End Select Next 'Delete the calendar message Wscript.Echo "Rs.Delete" ' Rs.Delete End If Rs.MoveNext Loop