VBA to get the office meeting room details in excel

sdsurzh

Active Member
Joined
Sep 27, 2009
Messages
251
Hi,
I have 5 different meeting rooms in my office, before i book a meeting, i want to know for a particular meeting room is occupied for how many hours and what time its free.
I need a VBA code to get these details in a excel sheet.
Thanks in advance,
Suresh Kumar S
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
How about:

VBA Code:
Sub RoomAvailability()
    Dim olApp As Object, olNamespace As Object, olFolder As Object
    Dim olRecip As Object, olCalendar As Object, olItems As Object, olAppt As Object
    Dim StartDate As Date, EndDate As Date, RoomName As String, Rooms As Variant
    Dim i As Integer, ws As Worksheet, row As Integer, dateStrFilter As String

    Set olApp = CreateObject("Outlook.Application")
    Set olNamespace = olApp.GetNamespace("MAPI")
    
    StartDate = Date
    EndDate = Date + 1
    
    Rooms = Array("MrExcel Room", "MrsExcel Room") 'Swap with your 5 room names
    
    Set ws = ThisWorkbook.Sheets("Sheet1") 'Change sheet name if you want it somewhere else
    ws.Columns("A").ClearContents
    row = 1
    
    'Loop through each room
    For i = LBound(Rooms) To UBound(Rooms)
        RoomName = Rooms(i)
        
        'Get the calendar folder for the room
        Set olRecip = olNamespace.CreateRecipient(RoomName)
        olRecip.Resolve
        If olRecip.Resolved Then
            Set olFolder = olNamespace.GetSharedDefaultFolder(olRecip, 9)
            Set olItems = olFolder.Items
            olItems.Sort "[Start]"
            olItems.IncludeRecurrences = True
            
            dateStrFilter = "[Start] >= '" & Format(StartDate, "ddddd h:nn AMPM") & "' AND [End] <= '" & Format(EndDate, "ddddd h:nn AMPM") & "'"
            Set olItems = olItems.Restrict(dateStrFilter)
            
            'Push information to Sheet1
            ws.Cells(row, 1).Value = "Availability for " & RoomName & ":"
            row = row + 1
            If olItems.Count = 0 Then
                ws.Cells(row, 1).Value = "No appointments found."
                row = row + 1
            Else
                For Each olAppt In olItems
                    ws.Cells(row, 1).Value = olAppt.Subject & " from " & olAppt.Start & " to " & olAppt.End
                    row = row + 1
                Next olAppt
            End If
        Else
            ws.Cells(row, 1).Value = "Could not resolve recipient: " & RoomName
            row = row + 1
        End If
    Next i
    
    Set olAppt = Nothing
    Set olItems = Nothing
    Set olFolder = Nothing
    Set olRecip = Nothing
    Set olNamespace = Nothing
    Set olApp = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,021
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top