Populate Calendars from Excel Data

Newbie_Nat

New Member
Joined
Jan 8, 2021
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hello
I've managed to get a script running to automatically send an email with holiday requests to employees but I now need to create an appointment in both the employees calendar and in a Public Folder calendar. This is my script so far, so just need to amend the folders side of things x2!! Any help would be much appreciated. Apologies in advance if I've not posted correctly!

VBA Code:
Dim xRg As Range
Private Sub Worksheet_Change(ByVal Target As Range)
    On Error Resume Next
    If Target.Cells.Count > 1 Then Exit Sub
  Set xRg = Intersect(Range("M5:M20"), Target)
    If xRg Is Nothing Then Exit Sub
    If Target.Value > 0 Then
        Call Mail_small_Text_Outlook(Target.Row)
    End If
End Sub

Sub Mail_small_Text_Outlook(ByVal TargetRow As Long)
    Dim xOutApp As Object
    Dim xOutMail As Object
    Dim xMailBody As String
    Dim wsActiveSheet As Worksheet

    
    Set xOutApp = CreateObject("Outlook.Application")
    Set xOutMail = xOutApp.CreateItem(0)
    Set wsActiveSheet = Application.ActiveSheet
   
     xMailBody = "Please accept this email As confirmation of your holiday booking - information As below" & vbNewLine & vbNewLine & _
                "Date of Request: " & CStr(wsActiveSheet.Cells(TargetRow, 6).Text) & vbNewLine & _
                "Number of Days Booked: " & CStr(wsActiveSheet.Cells(TargetRow, 5).Text) & vbNewLine & vbNewLine & _
                "2021 Leave Remaining as at today's date: " & CStr(wsActiveSheet.Cells(TargetRow, 8).Text) & " days" & vbNewLine & _
                "Data Entered By: " & CStr(wsActiveSheet.Cells(TargetRow, 13).Text) & vbNewLine & vbNewLine & _
                "Authorised By: " & CStr(wsActiveSheet.Cells(TargetRow, 7).Text) & vbNewLine & vbNewLine & _
                "Thank you"
   
    On Error Resume Next
    With xOutMail
        .To = CStr(wsActiveSheet.Cells(TargetRow, 14).Text)
        .CC = ""
        .BCC = ""
        .Subject = "Holiday Booking Confirmation"
        .Body = xMailBody
        .Display   'or use .Send
    End With
    On Error GoTo 0
    Set xOutMail = Nothing
    Set xOutApp = Nothing


Set olOutlook = CreateObject("Outlook.Application")
Set Namespace = olOutlook.GetNamespace("MAPI")
Set oloFolder = Namespace.GetDefaultFolder(9)

LastRow = Cells(Rows.Count, 2).End(xlUp).Row

For I = 5 To LastRow

    Description = CStr(wsActiveSheet.Cells(1, 2).Text)
    StartDate = Cells(I, 2).Value
    EndDate = Cells(I, 3).Value
    
    Set Appointment = oloFolder.items.Add
    
    With Appointment
        .Start = StartDate
        .End = EndDate
        .Subject = Description
        .Save
    
    End With

Next I
End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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