Newbie_Nat
New Member
- Joined
- Jan 8, 2021
- Messages
- 6
- Office Version
- 365
- Platform
- 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!
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