Hello,
I copied codefrom Diane Peremsky for flagging sent emails...I've put the code in a module...
Option Explicit
Private WithEvents olSentItems As Items
Private Sub Application_Startup()
Dim objNS As NameSpace
Set objNS = Application.Session
' instantiate objects declared WithEvents
Set olSentItems = objNS.GetDefaultFolder(olFolderSentMail).Items
Set objNS = Nothing
End Sub
Private Sub olSentItems_ItemAdd(ByVal Item As Object)
On Error Resume Next
Dim prompt As String
prompt$ = "Do you want to flag this message for followup?"
If MsgBox(prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Add flag?") = vbYes Then
With Item
> MarkAsTask olMarkThisWeek
' sets a due date in 3 days
> TaskDueDate = Now + 3
> ReminderSet = True
> ReminderTime = Now + 2
> Save
End With
End If
End Sub
When I run the code, I receive the following error: "Compile error: Only valid in object module". This happens with the Private WithEvents olSentItems as Items at the very beginning.
Why do I get this? Any help is appreciated.
Thank You
Laura
I copied codefrom Diane Peremsky for flagging sent emails...I've put the code in a module...
Option Explicit
Private WithEvents olSentItems As Items
Private Sub Application_Startup()
Dim objNS As NameSpace
Set objNS = Application.Session
' instantiate objects declared WithEvents
Set olSentItems = objNS.GetDefaultFolder(olFolderSentMail).Items
Set objNS = Nothing
End Sub
Private Sub olSentItems_ItemAdd(ByVal Item As Object)
On Error Resume Next
Dim prompt As String
prompt$ = "Do you want to flag this message for followup?"
If MsgBox(prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Add flag?") = vbYes Then
With Item
> MarkAsTask olMarkThisWeek
' sets a due date in 3 days
> TaskDueDate = Now + 3
> ReminderSet = True
> ReminderTime = Now + 2
> Save
End With
End If
End Sub
When I run the code, I receive the following error: "Compile error: Only valid in object module". This happens with the Private WithEvents olSentItems as Items at the very beginning.
Why do I get this? Any help is appreciated.
Thank You
Laura