On some items of type AppointmentItem, I can set the Start property either as data type String or Date, other items of same type (I verified this by use TypeName (item)), I get either 'object does not support method' (if item declared as Object) or 'type mismatch (if item declared as AppointmentItem). The best clue I can think of is some appointments are created via VBA - those work properly to set Start property. Appointments created via Outlook UI get the error trying to set the Start property. Visually both appointments (created by VBA or via Outlook UI) look the same - baffled by the randomness of the error.
I tried the following without success:
1) Declared item as AppointmentItem - error changed from "object does not support..." to "type mismatch"
2) Declared and passed NewDate as String
Here's the code:
Sub ResetApptStartTime()
Dim CalFolder As Folder
Dim folders As folders
Dim FolderCount As Integer, ItemCount As Integer
Dim NewDate As Date
'Set CalFolder = Session.GetDefaultFolder(olFolderCalendar)
Set CalFolder = ActiveExplorer.CurrentFolder
NewDate = Format(Now, "mm/dd/yyyy")
If (WeekdayName(Weekday(NewDate)) = "Saturday") Then
NewDate = DateAdd("d", 2, NewDate)
Else
If (WeekdayName(Weekday(NewDate)) = "Sunday") Then NewDate = DateAdd("d", 1, NewDate)
End If
NewDate = NewDate & " " & #11:59:00 PM#
ProcessCalFolders CalFolder, NewDate, FolderCount, ItemCount
Debug.Print "Folders processed: ", FolderCount, "Items processed: ", ItemCount
End Sub
Sub ProcessCalFolders(CalFolder As Folder, ByVal NewDate As Date, FolderCount As Integer, ItemCount As Integer)
Dim SubFolder As Folder
Dim PartialSubject As String
Dim PrevDate As Date
Dim item As Object
On Error GoTo ErrHandler
FolderCount = FolderCount + 1
For Each item In CalFolder.Items
If item.Class <> olAppointment Then MsgBox "The folder you selected contains non-appointment items, aborting": Exit Sub
PartialSubject = Left(item.Subject, 50)
PartialSubject = Replace(PartialSubject, vbCrLf, "")
PartialSubject = Replace(PartialSubject, vbLf, "")
Debug.Print PartialSubject
PrevDate = item.Start
If Now > PrevDate Then
item.Start = NewDate & " " & #6:00:00 AM# 'THIS LINE GENERATES THE ERROR
item.End = NewDate & " " & #6:00:00 AM#
' item.Save
Debug.Print "Subject: ", PartialSubject, "changed from ", PrevDate, " to ", item.Start
ItemCount = ItemCount + 1
End If
Next
For Each SubFolder In CalFolder.folders
ProcessCalFolders SubFolder, NewDate, FolderCount, ItemCount
Next
Exit Sub
ErrHandler:
Debug.Print Err.Number, Err.Description
Resume Next
End Sub
I tried the following without success:
1) Declared item as AppointmentItem - error changed from "object does not support..." to "type mismatch"
2) Declared and passed NewDate as String
Here's the code:
Sub ResetApptStartTime()
Dim CalFolder As Folder
Dim folders As folders
Dim FolderCount As Integer, ItemCount As Integer
Dim NewDate As Date
'Set CalFolder = Session.GetDefaultFolder(olFolderCalendar)
Set CalFolder = ActiveExplorer.CurrentFolder
NewDate = Format(Now, "mm/dd/yyyy")
If (WeekdayName(Weekday(NewDate)) = "Saturday") Then
NewDate = DateAdd("d", 2, NewDate)
Else
If (WeekdayName(Weekday(NewDate)) = "Sunday") Then NewDate = DateAdd("d", 1, NewDate)
End If
NewDate = NewDate & " " & #11:59:00 PM#
ProcessCalFolders CalFolder, NewDate, FolderCount, ItemCount
Debug.Print "Folders processed: ", FolderCount, "Items processed: ", ItemCount
End Sub
Sub ProcessCalFolders(CalFolder As Folder, ByVal NewDate As Date, FolderCount As Integer, ItemCount As Integer)
Dim SubFolder As Folder
Dim PartialSubject As String
Dim PrevDate As Date
Dim item As Object
On Error GoTo ErrHandler
FolderCount = FolderCount + 1
For Each item In CalFolder.Items
If item.Class <> olAppointment Then MsgBox "The folder you selected contains non-appointment items, aborting": Exit Sub
PartialSubject = Left(item.Subject, 50)
PartialSubject = Replace(PartialSubject, vbCrLf, "")
PartialSubject = Replace(PartialSubject, vbLf, "")
Debug.Print PartialSubject
PrevDate = item.Start
If Now > PrevDate Then
item.Start = NewDate & " " & #6:00:00 AM# 'THIS LINE GENERATES THE ERROR
item.End = NewDate & " " & #6:00:00 AM#
' item.Save
Debug.Print "Subject: ", PartialSubject, "changed from ", PrevDate, " to ", item.Start
ItemCount = ItemCount + 1
End If
Next
For Each SubFolder In CalFolder.folders
ProcessCalFolders SubFolder, NewDate, FolderCount, ItemCount
Next
Exit Sub
ErrHandler:
Debug.Print Err.Number, Err.Description
Resume Next
End Sub
Last edited: