I have the following code written to delete all appointments from a subfolder of the Outlook Calendar. I have struggled trying to find the right way to call this subfolder in the code and am now stumped. It now seems to be able to call the correct folder but is unable to proceed with deleting the appointments. I tested this code on the default Calendar successfully before trying to direct it towards the subfolder.
I have commented out the line of code below where I am receiving run-time error 438: "Object doesn't support this property or method".
I would appreciate anyone being able to let me know what I need to change to resolve this issue.
Public Sub DeleteAppt()
Dim olApp As Object 'Outlook.Application
Dim olNS As Object 'Outlook.Namespace
Dim olAptItemFolder As Object 'Outlook.Folder
Dim olAptItem As Object 'Outlook.AppointmentItem
Dim i As Long
Set olApp = CreateObject("Outlook.Application")
Set olNS = olApp.Session
Set olAptItemFolder = olNS.GetDefaultFolder(olFolderCalendar).Folders("TestCal").Items
''''For i = olAptItemFolder.Items.Count To 1 Step -1
Set olAptItem = olAptItemFolder.Items(i)
If olAptItem.Subject Like "***" Then
olAptItem.Delete
End If
Next i
Set olAptItem = Nothing
Set olAptItemFolder = Nothing
Set olApp = Nothing
End Sub
Change the line
For i = olAptItemFolder.Items.Count To 1 Step - 1
to
For i = olAptItemFolder.Count To 1 Step - 1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.