Consulting

Results 1 to 5 of 5

Thread: VBA Send Recurring Task In Email

  1. #1
    VBAX Tutor
    Joined
    Oct 2012
    Posts
    298
    Location

    VBA Send Recurring Task In Email

    Hi, I wonder whether someone may be able to help me please.

    Using this link http://www.slipstick.com/developer/c...nding-message/
    I've been able to put together the folllowing script which allows me to send a task via an email to chosen recipients.

    Public WithEvents myOlApp As Outlook.Application
    Private Sub Application_Startup()
        Initialize_handler
    End Sub
    Public Sub Initialize_handler()
        Set myOlApp = CreateObject("Outlook.Application")
    End Sub
    Private Sub myOlApp_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim intRes As Integer
    Dim strMsg As String
    Dim objTask As TaskItem
    Set objTask = Application.CreateItem(olTaskItem)
    Dim strRecip As String
     strMsg = "Do you want to create a task for this message?"
     intRes = MsgBox(strMsg, vbYesNo + vbExclamation, "Create Task")
    
        If intRes = vbNo Then
          Cancel = False
        Else
        For Each recipient In Item.Recipients
            strRecip = strRecip & vbCrLf & recipient.Address
        Next recipient
    With objTask
        .Body = strRecip & vbCrLf & Item.Body
        .Subject = Item.Subject
        .StartDate = Item.ReceivedTime
        .ReminderSet = True
        .ReminderTime = DateSerial(Year(Now), Month(Now), Day(Now)) + #7:23:00 AM#
        .Save
    End With
        Cancel = False
        End If
    Set objTask = Nothing
    End Sub
    What I'm now trying to do is amend this slightly so that the task is 'recurring' rather than a 'one off', creating a new task for every Friday at 1.00pm.

    I've spent a number of days trying to find a tutorial or solution for this, but I've been unable to do so.

    I just wondered whether someone could possibly look at this please and offer some guidance on how I may go about achieiving this.

    Many thanks and kind regards

  2. #2
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    This code sets up a task with a moving reminder to generate an email. Change the code to send weekly rather than daily.

    http://www.vboffice.net/sample.html?...0&cmd=showitem
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

  3. #3
    VBAX Tutor
    Joined
    Oct 2012
    Posts
    298
    Location
    Hi @skatonni, thank you very much for taking the time to reply to my post and for the link. It's exactly what I was after.

    All the best and kind regards

  4. #4
    VBAX Tutor
    Joined
    Oct 2012
    Posts
    298
    Location
    Hi @skatonni, I hope you are well.

    I just wanted to give you an update on the code you kindly provided the link to.

    Unfortumnately, this isn't what I was looking for. What I'm trying to do is send the email once, with the recurring task set up in the recipients 'Task' list.

    Many thanks and kind regards

  5. #5
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    For anyone with this question, rather than the kludgy two-part solution suggested, hobbiton73 has this. http://www.excelforum.com/outlook-pr...ring-task.html

    Public WithEvents myOlApp As Outlook.Application
    
    Private Sub Application_Startup()
        Initialize_handler
    End Sub
    
    Public Sub Initialize_handler()
        Set myOlApp = CreateObject("Outlook.Application")
    End Sub
    
    Private Sub myOlApp_ItemSend(ByVal Item As Object, Cancel As Boolean)
    
    Dim intRes As Integer
    Dim strMsg As String
    Dim objTask As TaskItem
    Set objTask = Application.CreateItem(olTaskItem)
    Dim strRecip As String
    
     strMsg = "Do you want to create a task for this message?"
     intRes = MsgBox(strMsg, vbYesNo + vbExclamation, "Create Task")
    
        If intRes = vbNo Then
          Cancel = False
        Else
    
        For Each recipient In Item.Recipients
            strRecip = strRecip & vbCrLf & recipient.Address
        Next recipient
    
    With objTask
        Set recpattern = .GetRecurrencePattern
        recpattern.RecurrenceType = olRecursWeekly
        recpattern.DayOfWeekMask = olMonday
        recpattern.PatternStartDate = #11/18/2013 9:00:00 AM#
        recpattern.Interval = 1
        .Body = strRecip & vbCrLf & Item.Body
        .Subject = Item.Subject
        .Save
    End With
    
    Cancel = False
    
        End If
    
    Set objTask = Nothing
    End Sub
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •