How do I add a recipient to a dynamically created Outlook Meeting using textbox data from an Excel Userform?

MerekThall

New Member
Joined
Sep 27, 2018
Messages
3
Hello.

I am trying to dynamically create an Outlook Meeting based on data entered into an Excel userform. I can pass data from other text and combo boxes to establish the start and end dates, location, etc. I am having an issue passing the textbox value for the recipient. Can anyone help me understand what I am doing wrong? The error I get is "Run-time error '287': Application-defined or object-defined error. The code below is attempting to create an email and a meeting, however my issue is with adding recipients to the meeting. In general, I plan to remove the code for creating an email as it was originally written as a means to test functionality passes the form data to Outlook.

Private Sub cmdToOutlook_Click()

Dim OutlookApp as Outlook.Application
Dim OutlookMail as Outlook.MailItem
Dim OutlookCal as Outlook.OlkDateControl

Set OutlookApp = New Outlook.Application
Set OutlookMail = OutlookApp.CreateItem(olMailItem)

With OutlookMail

.BodyFormat = olFormatHTML
.Display
.HTMLBody = "Write your email here"
.To = txtUserID.Value
.CC = txtMgr.Value & "; " & cbCoach.Value
.Subject = "Test Mail from User Form"

End With

Dim OutlookAppt as Outlook.AppointmentItem
Dim rRequiredAttendee as Outlook.Recipient
Dim address as Variant

address = txtUserID.Value

Set OutlookAppt = OutlookApp.CreateItem(olAppointmentItem)

With OutlookAppt

.MeetingStatus = olMeeting
Set rRequiredAttendee = .Recipients.Add(address) 'The error comes from this line
.Subject = "Training"
.Start = txtStartDate.Value
.End = txtEndDate.Value
.Location = "TBD"
.Display

End With

End Sub


Any help is greatly appreciated.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
I could run the code without any problems. I took out the email portion, but did not change anything else (except adding "me" in front of the Form Controls).

VBA Code:
Private Sub cmdToOutlook_Click()

    Dim OutlookApp As Outlook.Application
    Set OutlookApp = New Outlook.Application

    Dim OutlookAppt As Outlook.AppointmentItem
    Dim rRequiredAttendee As Outlook.Recipient
    Dim address As Variant

    address = Me.txtUserID.Value

    Set OutlookAppt = OutlookApp.CreateItem(olAppointmentItem)

    With OutlookAppt

        .MeetingStatus = olMeeting
        Set rRequiredAttendee = .Recipients.Add(address)
        .Subject = "Training"
        .Start = Me.txtStartDate.Value
        .End = Me.txtEndDate.Value
        .Location = "TBD"
        .Display

    End With

End Sub

Did you add the Outlook Object library to your VBA project references?
 
Upvote 0
JumpingCrab,

Thank you for your reply. I had the Outlook Object Library 16.0 included with my references. I still get the error with the Set rRequiredAttendee = .Recipients.Add(address). Recipients.Add has the UserID value from text textbox. rRequiredAttendee's value is Nothing. If I remove the .Recipients.Add, I can create the meeting without issue but it defeats the purpose of the macro (i.e. creating the appointment to include the UserID as the recipient). Based on the error, I don't know what I am overlooking in terms of ill-defining either the Application or Object. Looking through the forums before I started this thread, I saw references to security or anti-virus issues on the machine. I haven't come across corroboration though. Any thoughts?
 
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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