VBA excel dates to outlook meetings - ignore blank cells

Yosepht

New Member
Joined
Nov 19, 2019
Messages
33
Hey everyone,

I'm having a lot of trouble getting my head around VBA and I'm very stuck on this particular issue.
The code does excatly what i need it to, up until " Set RequiredAttendee = .Recipients.Add(Cells(i, 7).Value) " where some of the cells in that range are blank and I need it to ignore and still continue the operation.

I get "Run-Time Error: There must be at least one name or contact group in the To, Cc or Bcc box. Which stops the entire process.

Sorry if this is not how to post a problem as i'm new here.

VBA Code:
Public Sub CreateOutlookAppointments()
   Sheets("sheet1").Select
    On Error GoTo Err_Execute
    
    Dim olApp As Outlook.Application
    Dim olAppt As Outlook.AppointmentItem
    Dim blnCreated As Boolean
    Dim olNs As Outlook.Namespace
    Dim CalFolder As Outlook.MAPIFolder
    
    Dim i As Long
    
    On Error Resume Next
    Set olApp = Outlook.Application
    
    If olApp Is Nothing Then
        Set olApp = Outlook.Application
         blnCreated = True
        Err.Clear
    Else
        blnCreated = False
    End If
    
    On Error GoTo 0
    
    Set olNs = olApp.GetNamespace("MAPI")
    Set CalFolder = olNs.GetDefaultFolder(olFolderCalendar)
        
    i = 2
    Do Until Trim(Cells(i, 1).Value) = ""
    
    Set olAppt = CalFolder.Items.Add(olAppointmentItem)
    With olAppt
       .MeetingStatus = olMeeting
    'Define calendar item properties
        .Subject = Cells(i, 1)
        .Start = Cells(i, 3)
        .Categories = Cells(i, 4)
        .Body = Cells(i, 5)
        .AllDayEvent = True
        .BusyStatus = olFree
        .ReminderMinutesBeforeStart = 2880
        .ReminderSet = True
' get the recipients
        Dim RequiredAttendee As Outlook.Recipient
        Set RequiredAttendee = .Recipients.Add(Cells(i, 7).Value)
            RequiredAttendee.Type = olRequired
        .Display
    End With
        
        i = i + 1
        Loop
    Set olAppt = Nothing
    Set olApp = Nothing
    
    Exit Sub
    
Err_Execute:
    MsgBox "An error occurred - Exporting items to Calendar."
    
End Sub
' Above works for meetings but crashes when encountering empty recipient.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hi, again Domenic!

Sorry, let me rephrase. I have other appointments that need adding to my outlook calendar in the same table (e.g. Rows 14 & 15 below), however, the VBA currently only creates .olmeeting for appointments with attendees labelled.

How do I adapt the current code to add appointments that do not have attendees in column "F" to my outlook calendar as a personal appointment, while avoiding past dates in column C?

I hope this is a little clearer!
Annotation 2019-11-20 093104.png
 
Upvote 0
To create appointments for dates that are greater than or equal to today's date, and where there are no recipients specified, replace...

VBA Code:
If startDate >= Date And Len(theRecipients) > 0 Then

with

Code:
If startDate >= Date And Len(theRecipients) = 0 Then
 
Upvote 0

Forum statistics

Threads
1,215,504
Messages
6,125,185
Members
449,213
Latest member
Kirbito

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