P
Paul
Hi,
I'm using office 2003.
I'm using the code below to change the label for my appointments based on
the subject contents, but when I run the code not all the appointments are
changed to the assigned label. Some will stay white...
Any ideas anybody?
Cheers,
Paul
Sub Label()
Dim objOutlook As New Outlook.Application
Dim objNamespace As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Dim objAppointement As Outlook.AppointmentItem
Dim objAttachment As Outlook.Attachment
Dim objNetwork As Object
Dim lngDeletedAppointements As Long
Dim lngCleanedAppointements As Long
Dim lngCleanedAttachments As Long
Dim blnRestart As Boolean
Dim intDateDiff As Integer
Set objOutlook = Outlook.Application
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objFolder =
objNamespace.GetFolderFromID("00000000AAAEAB88111BB14FB3930A1FFF7C2A9101000EF192502C04154AB66E62534AEC6E18002B0EF780E70000")
For Each objAppointement In objFolder.Items
DoEvents
If objAppointement.Subject = "x" Then
Call SetApptColorLabel(objAppointement, 1)
ElseIf objAppointement.Subject = "y" Then
Call SetApptColorLabel(objAppointement, 2)
ElseIf objAppointement.Subject = "r" Then
Call SetApptColorLabel(objAppointement, 3)
ElseIf objAppointement.Subject = "t" Then
Call SetApptColorLabel(objAppointement, 4)
ElseIf objAppointement.Subject = "g" Then
Call SetApptColorLabel(objAppointement, 5)
End If
Next
End Sub
Sub SetApptColorLabel(objAppt As Object, _
intColor As Integer)
Const CdoPropSetID1 = "0220060000000000C000000000000046"
Const CdoAppt_Colors = "0x8214"
Dim objCDO As Object
Dim objMsg As Object
Dim colFields As Object
Dim objField As Object
Dim strMsg As String
Dim intAns As Integer
On Error Resume Next
Set objCDO = CreateObject("MAPI.Session")
objCDO.Logon "", "", False, False
If Not objAppt.EntryID = "" Then
Set objMsg = objCDO.GetMessage(objAppt.EntryID, objAppt.Parent.StoreID)
Set colFields = objMsg.Fields
Set objField = colFields.Item(CdoAppt_Colors, CdoPropSetID1)
If objField Is Nothing Then
Err.Clear
Set objField = colFields.Add(CdoAppt_Colors, vbLong, intColor, CdoPropSetID1)
Else
objField.Value = intColor
End If
objMsg.Update True, True
Else
strMsg = "You must save the appointment before you add a color label. " & _
"Do you want to save the appointment now?"
intAns = MsgBox(strMsg, vbYesNo + vbDefaultButton1, "Set Appointment Color
Label")
If intAns = vbYes Then
Call SetApptColorLabel(objAppt, intColor)
Else
Exit Sub
End If
End If
Set objAppt = Nothing
Set objMsg = Nothing
Set colFields = Nothing
Set objField = Nothing
objCDO.Logoff
Set objCDO = Nothing
End Sub
I'm using office 2003.
I'm using the code below to change the label for my appointments based on
the subject contents, but when I run the code not all the appointments are
changed to the assigned label. Some will stay white...
Any ideas anybody?
Cheers,
Paul
Sub Label()
Dim objOutlook As New Outlook.Application
Dim objNamespace As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Dim objAppointement As Outlook.AppointmentItem
Dim objAttachment As Outlook.Attachment
Dim objNetwork As Object
Dim lngDeletedAppointements As Long
Dim lngCleanedAppointements As Long
Dim lngCleanedAttachments As Long
Dim blnRestart As Boolean
Dim intDateDiff As Integer
Set objOutlook = Outlook.Application
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objFolder =
objNamespace.GetFolderFromID("00000000AAAEAB88111BB14FB3930A1FFF7C2A9101000EF192502C04154AB66E62534AEC6E18002B0EF780E70000")
For Each objAppointement In objFolder.Items
DoEvents
If objAppointement.Subject = "x" Then
Call SetApptColorLabel(objAppointement, 1)
ElseIf objAppointement.Subject = "y" Then
Call SetApptColorLabel(objAppointement, 2)
ElseIf objAppointement.Subject = "r" Then
Call SetApptColorLabel(objAppointement, 3)
ElseIf objAppointement.Subject = "t" Then
Call SetApptColorLabel(objAppointement, 4)
ElseIf objAppointement.Subject = "g" Then
Call SetApptColorLabel(objAppointement, 5)
End If
Next
End Sub
Sub SetApptColorLabel(objAppt As Object, _
intColor As Integer)
Const CdoPropSetID1 = "0220060000000000C000000000000046"
Const CdoAppt_Colors = "0x8214"
Dim objCDO As Object
Dim objMsg As Object
Dim colFields As Object
Dim objField As Object
Dim strMsg As String
Dim intAns As Integer
On Error Resume Next
Set objCDO = CreateObject("MAPI.Session")
objCDO.Logon "", "", False, False
If Not objAppt.EntryID = "" Then
Set objMsg = objCDO.GetMessage(objAppt.EntryID, objAppt.Parent.StoreID)
Set colFields = objMsg.Fields
Set objField = colFields.Item(CdoAppt_Colors, CdoPropSetID1)
If objField Is Nothing Then
Err.Clear
Set objField = colFields.Add(CdoAppt_Colors, vbLong, intColor, CdoPropSetID1)
Else
objField.Value = intColor
End If
objMsg.Update True, True
Else
strMsg = "You must save the appointment before you add a color label. " & _
"Do you want to save the appointment now?"
intAns = MsgBox(strMsg, vbYesNo + vbDefaultButton1, "Set Appointment Color
Label")
If intAns = vbYes Then
Call SetApptColorLabel(objAppt, intColor)
Else
Exit Sub
End If
End If
Set objAppt = Nothing
Set objMsg = Nothing
Set colFields = Nothing
Set objField = Nothing
objCDO.Logoff
Set objCDO = Nothing
End Sub