Book meeting in Outlook with VBA (by date range and check availability)

ferynd

New Member
Joined
Oct 27, 2017
Messages
1
I put together code so that I could add my own appointments via an Excel tracking log to my calendar. This works great when I'm just putting basic appointments in. However, I'm often setting meetings with several people on my team throughout the week.


I would like to expand the code that I have below so that I can input a date range when I would be willing to have the meeting as well as the duration of the meeting, and then have it check each persons availability as well as a static list of meeting room resources and book the first option it comes across. I would have the rooms listed in order of preference.


As an example: I would like to be able to type in a list of names from my address book that will be attending a 1 hour meeting. It can happen anytime from 8am - 5pm on Friday. I would like the macro to pick the first available time slot where there is a meeting room available as well as each attendee is available and send out the meeting invite.


The code I currently have is below:


Code:
    Sub RegisterAppointmentList()
        ' adds a list of appontments to the Calendar in Outlook
        Dim olApp As Outlook.Application
        Dim olAppItem As Outlook.AppointmentItem
        Dim r As Long
            
        On Error Resume Next
        Worksheets("Schedule").Activate
    
        Set olApp = GetObject("", "Outlook.Application")
        On Error GoTo 0
        If olApp Is Nothing Then
            On Error Resume Next
            Set olApp = CreateObject("Outlook.Application")
            On Error GoTo 0
            If olApp Is Nothing Then
                MsgBox "Outlook is not available!"
                Exit Sub
            End If
        End If
        
        r = 3 'first row with appointment data in the active worksheet
        
        Do While Cells(r, 1).Value = "booked"
            r = r + 1
        Loop
        
        Dim mysub, myStart, myEnd
        While Len(Cells(r, 2).Text) <> 0
            mysub = Cells(r, 2) ' & ", " & Cells(r, 3)
            myStart = DateValue(Cells(r, 5).Value) + Cells(r, 12).Value
            myEnd = DateValue(Cells(r, 5).Value) + Cells(r, 13).Value
            'DeleteTestAppointments mysub, myStart, myEnd
            Set olAppItem = olApp.CreateItem(olAppointmentItem) 'creates a new appointment
            With olAppItem
                'set default appointment values
                .Location = Cells(r, 3)
                .Body = Cells(r, 4)
                .ReminderSet = True
                .BusyStatus = Cells(r, 14)
                '.RequiredAttendees = "johndoe@microsoft.com"
                On Error Resume Next
                .Start = myStart
                .End = myEnd
                .Subject = mysub
                '.Attachments.Add
                .Location = Cells(r, 3).Value
                .Body = .Subject & ", " & Chr(10) & Chr(10) & Cells(r, 4).Value
                .ReminderSet = True
                .BusyStatus = Cells(r, 14)
                .Categories = Cells(r, 10) 'add this to be able to delete the testappointments
                On Error GoTo 0
                .Save 'saves the new appointment to the default folder
            End With
            Cells(r, 1).Value = "booked"
            r = r + 1
        Wend
        Set olAppItem = Nothing
        Set olApp = Nothing
        MsgBox "Done !"
    End Sub
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
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