M
Mark Milliman
I thought I had the problem licked until Outlook crashed and I lost my VBA
project. I recreated it quickly from memory. After a week of using the
recreated scripts, I noticed that the script that I have to set a new
appointment's color does not work. Well, sort of. The appointment is
colored in the calendar view. When I open the appointment, the label is set
to none.
I am using Redemption to bypass the security warnings from CDO. Instead of
using Sue's CDO code, I am using another function I found. I think my
problem is that I need to create the label first before setting it, but I am
not sure how to do that. Can someone point out the errors of my ways?
Public Sub WebinarAppt()
'This subroutine uses Redemption in various places
Dim objAppt
Dim objMsg
Dim oAItem, oMItem
Dim ErrFlag As Boolean
Dim dateStr, preambleStr, prologStr, subjectStr, timeStr As String
Dim dateStrLength As Integer
Dim timeOffset
Dim StartDate
ErrFlag = False
Set objMsg = CreateObject("Redemption.SafeMailItem")
Set oMItem = GetCurrentItem()
objMsg.Item = oMItem
Set objAppt = CreateObject("Redemption.SafeAppointmentItem")
Set oAItem = Application.CreateItem(olAppointmentItem)
objAppt.Item = oAItem
timeStr = "12:00 PM"
'Time difference from EST hardcoded to MST
timeOffset = -2
'Check to make sure that something was selected
If Not objMsg.Item Is Nothing Then
'Check to make sure that the selected item is a legitimate Webinar
message
strTest = Left(objMsg.Subject, 19)
If objMsg.Class = olMail And _
objMsg.SenderEmailAddress = "(e-mail address removed)" And _
StrComp(strTest, "LOG-IN INSTRUCTIONS", vbTextCompare) = 0 Then
'Parse message subject for subject of appointment
subjectStr = Trim(objMsg.Subject)
startPos = InStr(subjectStr, " - ") + 3
endPos = InStrRev(subjectStr, " - ")
strSize = endPos - startPos
subjectStr = Mid(subjectStr, startPos, strSize)
'Parse message subject for date of webinar
dateStrLength = Len(Trim(objMsg.Subject)) - (endPos + 2)
dateStr = Right(Trim(objMsg.Subject), dateStrLength)
'Parse the message body for the starting time
startPos = InStr(objMsg.HTMLBody, "<b>Time: ") + 9
endPos = InStr(startPos, objMsg.HTMLBody, "m.") + 2
strSize = endPos - startPos
timeStr = Mid(objMsg.HTMLBody, startPos, strSize)
timeStr = Replace(timeStr, ".", "")
If IsDate(dateStr) And IsDate(timeStr) Then
StartDate = DateAdd("h", timeOffset, CDate(dateStr & " " &
timeStr))
End If
'Parse message body
startPos = InStr(objMsg.HTMLBody, "Thank you for registering
") - 1
preambleStr = Left(objMsg.HTMLBody, startPos)
endPos = InStr(1, objMsg.HTMLBody, "London") + 19
strSize = Len(objMsg.HTMLBody)
prologStr = Mid(objMsg.HTMLBody, endPos, strSize)
With objAppt
.Subject = subjectStr
.Location = "Webinar"
.Start = StartDate
.Duration = 60
.ReminderMinutesBeforeStart = 5
.Categories = "Education"
.HTMLBody = preambleStr & prologStr
End With
objAppt.Save
Call SetColorCode(objAppt.Item, 5)
objAppt.Display
'objMsg.Delete 'deletes the message
Else
ErrFlag = True
End If
Else
ErrFlag = True
End If
If ErrFlag Then
MsgBox ("Please go to your Inbox and select a LightReading Webinar"
& vbCrLf & _
"invitation, then run again. A proper message was not selected.")
End If
'Clean up objects
Set oAItem = Nothing
Set oMItem = Nothing
Set objAppt = Nothing
Set objMsg = Nothing
End Sub
Function SetColorCode(olAppt As Outlook.AppointmentItem, lngColor As Long)
Const PT_LONG = &H3
Const PropSetID = "{00062002-0000-0000-C000-000000000046}"
Const ApptColors = "0x8214"
Dim lngPropID As Long
On Error Resume Next
Set oSafeAppt = CreateObject("Redemption.SafeAppointmentItem")
oSafeAppt.Item = olAppt
lngPropID = oSafeAppt.GetIDsFromNames(PropSetID, ApptColors) Or PT_LONG
MsgBox ("longPropID = " & lngPropID)
'The oSafeAppt.Fields(lngPropID) corresponds
'to the ordinal value of the label
'1=Important, 2=Business, etc.
oSafeAppt.Fields(lngPropID) = lngColor
olAppt.Save
End Function
Thanks,
Mark
--
________________________________
Mark Milliman
Longmont, Colorado E-mail: (e-mail address removed)
________________________________
project. I recreated it quickly from memory. After a week of using the
recreated scripts, I noticed that the script that I have to set a new
appointment's color does not work. Well, sort of. The appointment is
colored in the calendar view. When I open the appointment, the label is set
to none.
I am using Redemption to bypass the security warnings from CDO. Instead of
using Sue's CDO code, I am using another function I found. I think my
problem is that I need to create the label first before setting it, but I am
not sure how to do that. Can someone point out the errors of my ways?
Public Sub WebinarAppt()
'This subroutine uses Redemption in various places
Dim objAppt
Dim objMsg
Dim oAItem, oMItem
Dim ErrFlag As Boolean
Dim dateStr, preambleStr, prologStr, subjectStr, timeStr As String
Dim dateStrLength As Integer
Dim timeOffset
Dim StartDate
ErrFlag = False
Set objMsg = CreateObject("Redemption.SafeMailItem")
Set oMItem = GetCurrentItem()
objMsg.Item = oMItem
Set objAppt = CreateObject("Redemption.SafeAppointmentItem")
Set oAItem = Application.CreateItem(olAppointmentItem)
objAppt.Item = oAItem
timeStr = "12:00 PM"
'Time difference from EST hardcoded to MST
timeOffset = -2
'Check to make sure that something was selected
If Not objMsg.Item Is Nothing Then
'Check to make sure that the selected item is a legitimate Webinar
message
strTest = Left(objMsg.Subject, 19)
If objMsg.Class = olMail And _
objMsg.SenderEmailAddress = "(e-mail address removed)" And _
StrComp(strTest, "LOG-IN INSTRUCTIONS", vbTextCompare) = 0 Then
'Parse message subject for subject of appointment
subjectStr = Trim(objMsg.Subject)
startPos = InStr(subjectStr, " - ") + 3
endPos = InStrRev(subjectStr, " - ")
strSize = endPos - startPos
subjectStr = Mid(subjectStr, startPos, strSize)
'Parse message subject for date of webinar
dateStrLength = Len(Trim(objMsg.Subject)) - (endPos + 2)
dateStr = Right(Trim(objMsg.Subject), dateStrLength)
'Parse the message body for the starting time
startPos = InStr(objMsg.HTMLBody, "<b>Time: ") + 9
endPos = InStr(startPos, objMsg.HTMLBody, "m.") + 2
strSize = endPos - startPos
timeStr = Mid(objMsg.HTMLBody, startPos, strSize)
timeStr = Replace(timeStr, ".", "")
If IsDate(dateStr) And IsDate(timeStr) Then
StartDate = DateAdd("h", timeOffset, CDate(dateStr & " " &
timeStr))
End If
'Parse message body
startPos = InStr(objMsg.HTMLBody, "Thank you for registering
") - 1
preambleStr = Left(objMsg.HTMLBody, startPos)
endPos = InStr(1, objMsg.HTMLBody, "London") + 19
strSize = Len(objMsg.HTMLBody)
prologStr = Mid(objMsg.HTMLBody, endPos, strSize)
With objAppt
.Subject = subjectStr
.Location = "Webinar"
.Start = StartDate
.Duration = 60
.ReminderMinutesBeforeStart = 5
.Categories = "Education"
.HTMLBody = preambleStr & prologStr
End With
objAppt.Save
Call SetColorCode(objAppt.Item, 5)
objAppt.Display
'objMsg.Delete 'deletes the message
Else
ErrFlag = True
End If
Else
ErrFlag = True
End If
If ErrFlag Then
MsgBox ("Please go to your Inbox and select a LightReading Webinar"
& vbCrLf & _
"invitation, then run again. A proper message was not selected.")
End If
'Clean up objects
Set oAItem = Nothing
Set oMItem = Nothing
Set objAppt = Nothing
Set objMsg = Nothing
End Sub
Function SetColorCode(olAppt As Outlook.AppointmentItem, lngColor As Long)
Const PT_LONG = &H3
Const PropSetID = "{00062002-0000-0000-C000-000000000046}"
Const ApptColors = "0x8214"
Dim lngPropID As Long
On Error Resume Next
Set oSafeAppt = CreateObject("Redemption.SafeAppointmentItem")
oSafeAppt.Item = olAppt
lngPropID = oSafeAppt.GetIDsFromNames(PropSetID, ApptColors) Or PT_LONG
MsgBox ("longPropID = " & lngPropID)
'The oSafeAppt.Fields(lngPropID) corresponds
'to the ordinal value of the label
'1=Important, 2=Business, etc.
oSafeAppt.Fields(lngPropID) = lngColor
olAppt.Save
End Function
Thanks,
Mark
--
________________________________
Mark Milliman
Longmont, Colorado E-mail: (e-mail address removed)
________________________________