Consulting

Results 1 to 5 of 5

Thread: Recurrence Type of yearly evaluates to daily

  1. #1
    VBAX Newbie
    Joined
    Apr 2020
    Posts
    3
    Location

    Recurrence Type of yearly evaluates to daily

    I am writing VBA code to gather birthdays of clients from excel, and create birthday calendar appointment items in outlook, with a recurrence pattern of yearly. The code below works, with exception of creating an appointment item with a recurrence pattern of daily, instead of yearly. Stepping through each line, I noticed that the code changes the recurrence pattern from weekly to daily, rather than yearly, as expected. I am running Excel and Outlook 2016. Here is the code:

    Sub Birthday2()
    
    
    Dim objOutlook As Object
    Dim objnSpace As Object
    Dim objFolder As Object
    Dim myOccurencePattern As Object
    
    
    Set objOutlook = CreateObject("Outlook.Application")
    Set objnSpace = objOutlook.GetNamespace("MAPI")
    
        Set myApt = objOutlook.CreateItem(1)
             myApt.Subject = "Client Birthday"
             myApt.Body = #1/19/2020#
             myApt.Start = #1/19/2020#
             myApt.AllDayEvent = True
             myApt.ReminderMinutesBeforeStart = 10080
             
         Set myOccurencePattern = myApt.GetRecurrencePattern
        
            
             myOccurencePattern.RecurrenceType = olRecursYearly
             myOccurencePattern.PatternStartDate = #1/19/2020#
             myOccurencePattern.PatternEndDate = #1/19/2021#
             
             
          myApt.Save
             
    End Sub

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Since this was primarily an Outlook question, I moved it to the Outlook forum

    You'll probably get more attention in this forum
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Newbie
    Joined
    Apr 2020
    Posts
    3
    Location
    Thank You.

  4. #4
    You can't use Outlook specific commands when processing using late binding to Outlook from Excel thus olRecursYearly is ignored. Use instead the numeric equivalent (5).

    Sub Birthday2()
    
    
    Dim objOutlook As Object
    Dim objnSpace As Object
    Dim objFolder As Object
    Dim myApt As Object
    Dim myOccurencePattern As Object
    
    
        Set objOutlook = CreateObject("Outlook.Application")
        Set objnSpace = objOutlook.GetNamespace("MAPI")
    
        Set myApt = objOutlook.CreateItem(1)
        myApt.Subject = "Client Birthday"
        myApt.Body = #1/19/2020#
        myApt.Start = #1/19/2020#
        myApt.AllDayEvent = True
        myApt.ReminderMinutesBeforeStart = 10080
    
        Set myOccurencePattern = myApt.GetRecurrencePattern
    
    
        myOccurencePattern.RecurrenceType = 5
        myOccurencePattern.PatternStartDate = #1/19/2020#
        myOccurencePattern.PatternEndDate = #1/19/2021#
    
    
        myApt.Save
    
        Set objOutlook = Nothing
        Set objnSpace = Nothing
        Set myOccurencePattern = Nothing
        Set myApt = Nothing
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  5. #5
    VBAX Newbie
    Joined
    Apr 2020
    Posts
    3
    Location
    Thanks so much. I need to learn more about early and late binding. Thanks again.

Posting Permissions

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