PDA

View Full Version : Sending email with follow up



Sibrulotte
11-05-2010, 07:27 AM
Hi, it's a realy stupid task I need to do:
I don't want to getthe mouse and click "follow-up this week" when i send certain emails.
So my plan was to create a macro, and assign a keyboard shortcut

I found this big old code to create follow ups tasks...
but it's not eraly what I need to do.



Sub CreateFollowUpTask()
'
' you can specify how many (business) days later you want the reminder
'
' don't forget to include the 'NextBusinessDay' function as well, if you copy
' this code somewhere else
'
Dim objNS As Outlook.NameSpace
Set objNS = Application.GetNamespace("MAPI")
Dim objItem As Outlook.MailItem
Dim objTask As Outlook.TaskItem
Dim NumOfDays As Integer
Dim DayToRemind As Date
Const attPath As String = "C:\"
' set reference to email being viewed
'
' if we are running this code from the Inbox, then no email would be
' displayed, so we'll try to check the selection first
'
On Error Resume Next
Set objItem = Outlook.ActiveInspector.CurrentItem
If objItem Is Nothing Then
' we are probably in the explorer window
If (ActiveExplorer.Selection.Count = 1) And _
(ActiveExplorer.Selection.Item(1).Class = olMail) Then
Set objItem = ActiveExplorer.Selection.Item(1)
End If
End If
On Error GoTo 0
If objItem Is Nothing Then
' no email was displayed and no email was selected from the explorer window,
' cannot set reference to anything
MsgBox "I was not able to create a task. Please run this code ONLY " & _
"under one of the following conditions:" & vbCr & vbCr & _
"-- You are viewing an email message." & vbCr & _
"-- You are in your Inbox and have exactly one message selected.", _
vbInformation
GoTo ExitProc
End If
Set objTask = Outlook.CreateItem(olTaskItem)
' ask for days input
NumOfDays = InputBox("How many business days until reminder?")
' get date of next business day using function below
DayToRemind = NextBusinessDay(Format(Now, "M/D/YYYY"), NumOfDays)
With objTask
.StartDate = DayToRemind
.Subject = "Reminder For Followup: " & objItem.Subject
.Status = olTaskInProgress
.Importance = objItem.Importance
.DueDate = DayToRemind
.ReminderSet = True
' embed original email in the task
'
' first, save message copy
objItem.SaveAs attPath & objItem.EntryID
' then, embed message copy
objTask.Attachments.Add attPath & objItem.EntryID, olEmbeddeditem, , "Original Message"
' last, delete saved copy
Kill (attPath & objItem.EntryID)
.Save
End With
ExitProc:
End Sub

Function NextBusinessDay(dteDate As Date, intAhead As Integer) As Date
Dim dteNextDate As Date
dteNextDate = DateAdd("d", intAhead, dteDate)
Select Case Weekday(dteNextDate)
' if Sunday, add 1 day to make it next business day (Monday)
Case 1
dteNextDate = dteNextDate + 1
' if Saturday, add 2 days to make it next business day (Monday)
Case 7
dteNextDate = dteNextDate + 2
End Select
NextBusinessDay = dteNextDate
End Function




Does it have to do with mailitem.flagrequest ?
I've coded in excel and acess, but this is my first dip in Outlook.

Can you help?


Ha, I just tried to press Shift-enter to post...

Sebastian H
11-06-2010, 01:54 PM
but it's not eraly what I need to do.

Since it's hard for us to second guess your needs, we need a bit more input from you. What exactly do you want to do differently from the code; how did you adjust the code to your needs, and where exactly are you stuck?