Consulting

Results 1 to 3 of 3

Thread: Day of year count into Outlook

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Newbie
    Joined
    Feb 2020
    Posts
    2
    Location

    Question Day of year count into Outlook

    I'd like my Outlook O365 calendar to show the day number of the year for each day (e.g. today is 2/5/2020 so show 36 of 366 as this is leap year) which is not a native function in Outlook.

    I figured out the VBA code to calculate this. How can I get the results to show up for each day? Maybe a macro to insert a "not busy" appointment at 7:00 AM each day?

    Thanks,
    Chris

    In case anyone is interested the code is:

    Sub DayOfYrCt()


    Dim intDayNmbr As Integer
    Dim dt As Date: dt = Date
    intDayNmbr = DateDiff("d", CDate("1/1/" & Year(dt)), dt) + 1


    Dim LongDaysInYr As Long
    LongDaysInYr = 365 - (Year(dt) Mod 4 = 0) + (Year(dt) Mod 100 = 0) - (Year(dt) Mod 400 = 0)


    'Debug.Print intDayNmbr; "of"; LongDaysInYr


    End Sub

  2. #2
    Frankly I wouldn't attempt to do that. As calendars are volatile and effectively indefinite in scope, such a plan is likely to bring Outlook to a shuddering halt. Instead I would suggest using a macro attached to a ribbon button that will give you the day number of the selected date. The following will do that.
    Public Sub DayOfYrCt()
    
    'Graham Mayor - https://www.gmayor.com - Last updated - 07 Feb 2020
    Dim oView As Outlook.View
    Dim oCalView As Outlook.CalendarView
    Dim oExpl As Outlook.Explorer
    Dim oFolder As Outlook.Folder
    Dim intDayNmbr As Integer
    Dim dt As Date
    Dim LongDaysInYr As Long
    
        On Error GoTo err_Handler
        Set oExpl = Application.ActiveExplorer
        Set oFolder = Application.ActiveExplorer.CurrentFolder
        Set oView = oExpl.CurrentView
    
        If oView.ViewType = olCalendarView Then
            Set oCalView = oExpl.CurrentView
            dt = oCalView.SelectedStartTime
    
            intDayNmbr = DateDiff("d", CDate("1/1/" & Year(dt)), dt) + 1
            LongDaysInYr = 365 - (Year(dt) Mod 4 = 0) + (Year(dt) Mod 100 = 0) - (Year(dt) Mod 400 = 0)
            Beep
            MsgBox dt & ": Day " & intDayNmbr & " of " & LongDaysInYr
        End If
    lbl_Exit:
        Set oExpl = Nothing
        Set oFolder = Nothing
        Set oView = Nothing
        Set oCalView = Nothing
        Exit Sub
    err_Handler:
        Beep
        MsgBox "Select a date in the calendar before running this process!"
        Err.Clear
        GoTo lbl_Exit
    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

  3. #3
    VBAX Newbie
    Joined
    Feb 2020
    Posts
    2
    Location

    Thumbs up Solved: Day of Year count into Outlook

    Graham,
    This will do just what I need.
    thanks very much
    Chris

Tags for this Thread

Posting Permissions

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