How to modify this working code to switch from item notification trigger to event specific trigger? Basically from Private Sub (Item as Object) to Sub()
Being a noob and coming from powerapps, I can't make it work after converting it into a public sub (). Not able to initiate the if condition this way.
This code runs whenever a reminder is fired. Instead I want this to find the event as per my 'if condition' matching a subject string: "Bot invitation" and Schedule from <09:00 to 10:00>.
Private Sub Application_Reminder(ByVal Item As Object)
Dim objMeeting As Outlook.AppointmentItem
Dim objAttendees As Outlook.Recipients
Dim objAttendee As Outlook.Recipient
Dim objExcelApp As Excel.Application
Dim objExcelWorkbook As Excel.Workbook
Dim objExcelWorksheet As Excel.Worksheet
Dim strExcelFile As String
Dim nLastRow As Integer
Dim strTempFolder As String
Dim objShell, objFileSystem As Object
Dim objTempFolder, objTempFolderItem As Object
If InStr(LCase(Item.subject), "bot invitation") > 0 And TimeValue(Item.Start) = TimeValue("09:00:00 AM") Then
Set objMeeting = Item
Set objAttendees = objMeeting.Recipients
'On Error Resume Next
'Create a new Excel file
Set objExcelApp = CreateObject("Excel.Application")
Set objExcelWorkbook = objExcelApp.Workbooks.Add
Set objExcelWorksheet = objExcelWorkbook.Sheets("Sheet1")
objExcelWorksheet.Cells(1, 1) = "Name"
objExcelWorksheet.Cells(1, 2) = "Type"'objExcelWorksheet.Cells(1, 3) = "Email Address"
objExcelWorksheet.Cells(1, 3) = "Response"'Item.subject = Nothing
'Item.Start = Nothing
If objAttendees.Count > 0 Then
For Each objAttendee In objAttendees
nLastRow = objExcelWorksheet.Range("A"& objExcelWorksheet.Rows.Count).End(xlUp).Row + 1
'Input the attendee names
objExcelWorksheet.Range("A"& nLastRow) = objAttendee.Name
'Input the type of attendees
Select Case objAttendee.Type
Case "1"
objExcelWorksheet.Range("B"& nLastRow) = "Required Attendee"
Case "2"
objExcelWorksheet.Range("B"& nLastRow) = "Optional Attendee"
End Select
'Input the email addresses of attendees
'objExcelWorksheet.Range("C"& nLastRow) = objAttendee.Address
'Input the responses of attendees
Select Case objAttendee.MeetingResponseStatus
Case olResponseAccepted
objExcelWorksheet.Range("C"& nLastRow) = "Accept"
Case olResponseDeclined
objExcelWorksheet.Range("C"& nLastRow) = "Decline"
Case olResponseNotResponded
objExcelWorksheet.Range("C"& nLastRow) = "Not Respond"
Case olResponseTentative
objExcelWorksheet.Range("C"& nLastRow) = "Tentative"
End Select
Next
End If
'Fit the columns from A to D
objExcelWorksheet.Columns("A:C").AutoFit
'Set rng = Selection.SpecialCells(xlCellTypeVisible)
'You can also use a range if you want
'Set rng = objExcelWorksheet.Range("A1:C50").SpecialCells(xlCellTypeVisible)
objExcelWorksheet.ListObjects.Add(xlSrcRange, objExcelWorksheet.Range("A$1:$C$40"), , xlYes).Name = "Attendees"'Ws.ListObjects.Add(xlSrcRange, Ws.Range("A$1:$BE$1500"), , xlYes).Name = "New_Table_Name"
objExcelWorksheet.ListObjects("Attendees").TableStyle = "TableStyleLight1"'Save the Excel file in a temp folder
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
'strTempFolder = objFileSystem.GetSpecialFolder(2).Path & "\temp "& Format(Now, "yyyy-mm-dd hh-mm-ss")
'MkDir (strTempFolder)
strExcelFile = "mylink"& "\Attendee List for "& Item.subject & " ("& Format(Now, "yyyy-mm-dd") & ").xlsx"
objExcelWorkbook.Close True, strExcelFile
End If
'Print the Excel file
'Set objShell = CreateObject("Shell.Application")
'Set objTempFolder = objShell.NameSpace(0)
'Set objTempFolderItem = objTempFolder.ParseName(strExcelFile)
'objTempFolderItem.InvokeVerbEx ("print")
'Delete the temp folder and temp Excel file
'objFileSystem.DeleteFolder (strTempFolder)
End Sub