If you wish to rapidly get the list of free days for a specific month in your Outlook calendar, you can make use of the method exposed in this article. It can use VBA to print out the list within seconds.
With your Outlook calendar stuff with various appointments and meetings, you may desire to quickly extract a list of free days. Therefore, in the followings, we’ll share a piece of VBA code with you, which is able to find out all the free days in a specific month and print out the list of these free days straightly. Now read on to get the elaborate steps.
Print the List of Free Days for a Specific Month in Your Calendar
- For a start, launch your Outlook program.
- Then, after entering Outlook window, you need to press “Alt + F11” keys.
- Next in the subsequent “Microsoft Visual Basic for Applications” window, you can open a blank module.
- After that, copy the following VBA code into this module window.
Sub PrintFreeDaysinSpecificMonth() Dim strMonth As String Dim dFirstDate As Date Dim nDay As Integer Dim i As Long Dim strFreeDays As String Dim objAppointments As Outlook.Items Dim objFoundAppointment As Outlook.AppointmentItem Dim strFilter As String Dim objFileSystem As Object Dim strTextFile As String Dim objTextFile As Object 'Enter the specific month strMonth = InputBox("Enter the month, such as 7 or July:") 'Get the first date of the specific month in current year dFirstDate = CDate(strMonth & " 1, " & Year(Date)) strFreeDays = "Your Free Days in " & strMonth & ", " & Year(Date) & ":" & vbCrLf & vbCrLf & vbCrLf i = 0 For nDay = 0 To 30 'Get all appointments in the default Outlook calendar Set objAppointments = Application.Session.GetDefaultFolder(olFolderCalendar).Items objAppointments.Sort "[Start]" objAppointments.IncludeRecurrences = True strFilter = "[Start] >= '" & Format(dFirstDate + nDay, "M/D/YYYY") & "' And [Start] < '" & Format(dFirstDate + nDay + 1, "M/D/YYYY") & "'" 'Find the appointment in each day Set objFoundAppointment = objAppointments.Find(strFilter) 'If there is no appointment in the day If objFoundAppointment Is Nothing Then i = i + 1 'Input into the list of free days strFreeDays = strFreeDays & i & ": " & Format(dFirstDate + nDay, "M/D/YYYY") & vbCrLf End If Next strFreeDays = strFreeDays & vbCrLf & vbCrLf & "You have " & i & " free days in " & strMonth & ", " & Year(Date) & " in total!" 'Create a new Text file Set objFileSystem = CreateObject("Scripting.FileSystemObject") strTextFile = "E:\Your Free Days in " & strMonth & " " & Year(Date) & ".txt" Set objTextFile = objFileSystem.CreateTextFile(strTextFile, True) 'Input the list of free days into this Text file objTextFile.WriteLine (strFreeDays) objTextFile.Close 'Print the Text file Shell ("notepad.exe /p " & strTextFile) 'Delete the Text file objFileSystem.DeleteFile (strTextFile) End Sub
- Later you ought to insure that macros are enabled in your Outlook.
- Ultimately, you can try this new macro simply by press F5 key button in this module window.
- At once, you’ll be demanded to input the specific month, such as 7 or July.
- Finally, a list of free days in the specified month will be print out. It will look like the following screenshot:
Watch out for Every Outlook Error
Despite packed with myriad excellent features, errors can occur to Outlook now and then. Thus, you should beware of these errors. Mounting errors can lead to serious Outlook crashes one day. And in the event of crashes, even Scanpst will not be able to rescue your Outlook any more. At that point, your last resort is to employ a well-quality external tool, such as DataNumen Outlook Repair.
Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including damaged mdf and outlook repair software products. For more information visit www.datanumen.com