Log in

View Full Version : Day of year count into Outlook



Chri3sss
02-05-2020, 07:57 AM
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

gmayor
02-07-2020, 05:19 AM
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

Chri3sss
02-07-2020, 08:40 AM
Graham,
This will do just what I need.
thanks very much
Chris :hi: