+ Reply to Thread
Results 1 to 5 of 5

VBA Recurring Task

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    682

    VBA Recurring Task

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

    Firstly, my apologies this is my first Outlook macro, so it may contain many errors.

    But, I'm trying to create a recurring Task which I will send to other users via email with the following schedule:

    • Starting today i.e the 15/11/13
    • Send the reminder on the following Monday at 9.00am
    • Repeat each week

    '****Create a task in users Tasks Development****
    
    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
    
        .RecurrenceType = olRecursWeekly
        .DayOfWeekMask = olMonday
        .StartDate = #11/15/2013 2:00:00 PM#
        .Interval = 1
        .ReminderSet = True
        .ReminderTime = DayOfWeekMask + #9:00:00 AM#
        .Body = strRecip & vbCrLf & Item.Body
        .Subject = Item.Subject
        .Save
    End With
    
        Cancel = False
    
        End If
    
    Set objTask = Nothing
    End Sub
    The problem I have is that when I try to run this I receive the following: 'Run time error '483' Object doesn't this property or method' and Debug highlights this row as the cause:
    .RecurrenceType = olRecursWeekly
    I just wondered whether someone could possibly look at this please and let me knwo where I've gone wrong.

    Many thanks and kind regards

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA Recurring Task

    RecurrenceType is not a property of the mail item, it's a property of the recurrencepattern. So I think you need
    .GetRecurrencePattern.RecurrenceType = olRecurs Weekly
    I'm not 100% sure that works, you might need to set an object to the recurrence pattern and then change it, the help file says:
    Set myItem = Application.CreateItem(3)
    Set myPattern = myItem.GetRecurrencePattern
    myPattern.RecurrenceType = 2
    myPattern.Regenerate = True
    myPattern.Interval = 3
    myItem.Subject = "Oil Change"
    myItem.Save
    myItem.Display

  3. #3
    Forum Contributor
    Join Date
    05-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    682

    Re: VBA Recurring Task

    Hi yudlugar, thank you for taking the time to reply to my psot with code.

    I did try your intital suggestion, and as you suspected, this created the same error.

    I too, had looked at the help you've kindly highlighted, but I just wasn't sure how to amend this to suit my needs.

    Many thanks and kind regards

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA Recurring Task

    With objTask
        Set recpattern = .GetRecurrencePattern
        recpattern.RecurrenceType = olRecursWeekly

  5. #5
    Forum Contributor
    Join Date
    05-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    682

    Re: VBA Recurring Task

    Hi @yudlugar, thank you very mcuh for coming back to me with this and for getting me started.

    With your help, I've been able to put the following code together:


    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
    All the best and kind regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Recurring Task / Delayed Email in Outlook 2010
    By sme001 in forum Outlook Formatting & Functions
    Replies: 0
    Last Post: 03-12-2013, 11:41 AM
  2. VBA Excel/Email Recurring Task help!
    By jsabo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-29-2012, 05:55 PM
  3. [SOLVED] IF contingent task closed, THEN change formatting of dependent task cell
    By tek_9 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-29-2012, 08:40 PM
  4. Previous Task and Next Task buttons aren't working
    By top.C.Crets in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-07-2012, 08:27 AM
  5. dialog box for active cell task to speed repeditive task
    By Todd F. in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-09-2005, 10:05 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1