Outlook meeting cancelling using VBA - vba

There are instances when we forget to cancel a meeting which we scheduled, maybe due to absence of someone important, or maybe due to lack of time. But in many cases we forget to cancel the meeting from outlook. So, I am looking for a VBA code which will ask the organizer of a meeting if the meeting is good to go, or if it is to be cancelled, and will send out a cancellation mail if it is to be cancelled. Please help me with this. Thanks in advance! :)

After using the code from #alina as well as some other macro's from around the web, I came up with a solution for the same which i am sharing here.
Public WithEvents objReminders As Outlook.Reminders
Sub Initialize_handler()
Set objReminders = Application.Reminders
End Sub
Private Sub objReminders_ReminderFire(ByVal ReminderObject As reminder)
Dim oApp As Outlook.Application
Dim oNameSpace As Outlook.NameSpace
Dim oApptItem As Outlook.AppointmentItem
Dim oFolder As Outlook.MAPIFolder
Dim oMeetingoApptItem As Outlook.MeetingItem
Dim oObject As Object
Dim iUserReply As VbMsgBoxResult
Dim sErrorMessage As String
MsgBox (VBA.Time)
On Error Resume Next
' check if Outlook is running
Set oApp = GetObject("Outlook.Application")
If Err <> 0 Then
'if not running, start it
Set oApp = CreateObject("Outlook.Application")
End If
On Error GoTo Err_Handler
Set oNameSpace = oApp.GetNamespace("MAPI")
Set oFolder = oNameSpace.GetDefaultFolder(olFolderCalendar)
For Each oObject In oFolder.Items
If oObject.Class = olAppointment Then
Set oApptItem = oObject
If ReminderObject.Caption = oApptItem.Subject Then
If oApptItem.Organizer = Outlook.Session.CurrentUser Then
iUserReply = MsgBox("Meeting found:-" & vbCrLf & vbCrLf _
& Space(4) & "Date/time (duration): " & Format(oApptItem.Start, "dd/mm/yyyy hh:nn") _
& " (" & oApptItem.Duration & "mins)" & Space(10) & vbCrLf _
& Space(4) & "Subject: " & oApptItem.Subject & Space(10) & vbCrLf _
& Space(4) & "Location: " & oApptItem.Location & Space(10) & vbCrLf & vbCrLf _
& "Do you want to continue with the meeting?", vbYesNo + vbQuestion + vbDefaultButton1, "Meeting confirmation")
If iUserReply = vbNo Then
oApptItem.MeetingStatus = olMeetingCanceled
oApptItem.Save
oApptItem.Send
oApptItem.Delete
End If
End If
End If
End If
Next oObject
Set oApp = Nothing
Set oNameSpace = Nothing
Set oApptItem = Nothing
Set oFolder = Nothing
Set oObject = Nothing
Exit Sub
Err_Handler:
sErrorMessage = Err.Number & " " & Err.Description
End Sub

I found this here
Public Function DeleteAppointments(ByVal subjectStr As String)
Dim oOL As New Outlook.Application
Dim oNS As Outlook.NameSpace
Dim oAppointments As Object
Dim oAppointmentItem As Outlook.AppointmentItem
Dim iReply As VbMsgBoxResult
Set oNS = oOL.GetNamespace("MAPI")
Set oAppointments = oNS.GetDefaultFolder(olFolderCalendar)
Count = oAppointments.Items.Count 'for test purposes
For Each oAppointmentItem In oAppointments.Items
If InStr(oAppointmentItem.Subject, subjectStr) > 0 Then
iReply = msgbox("Appointment found:" & vbCrLf & vbCrLf _
& Space(4) & "Date/time: " & Format(oAppointmentItem.Start, "dd/mm/yyyy hh:nn") & vbCrLf _
& Space(4) & "Subject: " & oAppointmentItem.Subject & Space(10) & vbCrLf & vbCrLf _
& "Delete this appointment?", vbYesNo + vbQuestion + vbDefaultButton2, "Delete Appointment?")
If iReply = vbYes Then oAppointmentItem.Delete
oAppointmentItem.Delete
End If
Next
Set oAppointmentItem = Nothing
Set oAppointments = Nothing
Set oNS = Nothing
Set oOL = Nothing
End Function

Related

How to trigger event when an appointment is added/changed in a custom calendar?

The following code will automatically send the body of the appointment (be it newly created or just modified) to MySQL (into the table called report, under the column called BODY), if the appointment is in the default calendar.
Option Explicit
Private objNS As Outlook.NameSpace
Private WithEvents objItems As Outlook.Items
Private WithEvents objItems2 As Outlook.Items
Private Sub Application_Startup()
Dim objWatchFolder As Outlook.Folder
Set objNS = Application.GetNamespace("MAPI")
'Set the folder and items to watch:
Set objWatchFolder = objNS.GetDefaultFolder(olFolderCalendar)
Set objItems = objWatchFolder.Items
Set objItems2 = objWatchFolder.Items
Set objWatchFolder = Nothing
End Sub
Private Sub objItems_ItemAdd(ByVal Item As Object)
' Your code goes here
' MsgBox "Message subject: " & Item.Subject & vbCrLf & "Message sender: " & Item.SenderName & " (" & Item.SenderEmailAddress & ")"
' https://www.slipstick.com/developer/itemadd-macro
MsgBox "*** PROPERTIES of olFolderCalendar ***" & vbNewLine & _
"Subject: " & Item.Subject & vbNewLine & _
"Start: " & Item.Start & vbNewLine & _
"End: " & Item.End & vbNewLine & _
"Duration: " & Item.Duration & vbNewLine & _
"Location: " & Item.Location & vbNewLine & _
"Body: " & Item.Body & vbNewLine & _
"Global Appointment ID: " & Item.GlobalAppointmentID
send2mysql Item
Set Item = Nothing
End Sub
Private Sub objItems2_ItemChange(ByVal Item As Object)
MsgBox "*** PROPERTIES of olFolderCalendar ***" & vbNewLine & _
"Subject: " & Item.Subject & vbNewLine & _
"Start: " & Item.Start & vbNewLine & _
"End: " & Item.End & vbNewLine & _
"Duration: " & Item.Duration & vbNewLine & _
"Location: " & Item.Location & vbNewLine & _
"Body: " & Item.Body & vbNewLine & _
"Global Appointment ID: " & Item.GlobalAppointmentID
send2mysql Item
Set Item = Nothing
End Sub
Sub send2mysql(ByVal Item As Object)
Dim updSQL As String
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
Dim rs As ADODB.Recordset
Dim strConn As String
strConn = "Driver={MySQL ODBC 8.0 ANSI Driver};Server=localhost; Database=thairis; UID=root; PWD=root"
cn.Open strConn
updSQL = "INSERT INTO report (BODY) VALUES ('" & Item.Body & "')"
cn.Execute updSQL
MsgBox updSQL
MsgBox "Done"
End Sub
If I create or modify an appointment in a custom calendar (for example "My Test Calendar"), nothing is triggered.
Question: How do I have the above code respond to objItems_ItemAdd or objItems_ItemModify for any custom calendar in addition to the default calendar?
I use offline Desktop version Outlook 2016 on Windows 10 (64 bit).
You need to open the folder in question. Assuming "My Test Calendar" is a subfolder of the default calendar folder, your code would be
Set objItems2 = objNS.GetDefaultFolder(olFolderCalendar).Folders("My Test Calendar").Items
You need to retrieve calendar folders and their Items collection to get the events fired. For example, here is what I see for the default calendar folder:
'Set the folder and items to watch:
Set objWatchFolder = objNS.GetDefaultFolder(olFolderCalendar)
Set objItems = objWatchFolder.Items
You can iterate over all folder in Outlook to find calendar folders by using the Folder.DefaultItemType property which will have the olAppointmentItem value for calendars.
Also you can get calendars using the navigation module in Outlook:
Dim WithEvents objPane As NavigationPane
Private Sub EnumerateActiveCalendarFolders()
Dim objModule As CalendarModule
Dim objGroup As NavigationGroup
Dim objFolder As NavigationFolder
Dim intCounter As Integer
On Error GoTo ErrRoutine
' Get the NavigationPane object for the
' currently displayed Explorer object.
Set objPane = Application.ActiveExplorer.NavigationPane
' Get the CalendarModule object, if one exists,
' for the current Navigation Pane.
Set objModule = objPane.Modules.GetNavigationModule(olModuleCalendar)
' Iterate through each NavigationGroup contained
' by the CalendarModule.
For Each objGroup In objModule.NavigationGroups
' Iterate through each NavigationFolder contained
' by the NavigationGroup.
For Each objFolder In objGroup.NavigationFolders
' Check if the folder is selected.
If objFolder.IsSelected Then
intCounter = intCounter + 1
End If
Next
Next
' Display the results.
MsgBox "There are " & intCounter & " selected calendars in the Calendar module."
EndRoutine:
On Error GoTo 0
Set objFolder = Nothing
Set objGroup = Nothing
Set objModule = Nothing
Set objPane = Nothing
intCounter = 0
Exit Sub
ErrRoutine:
MsgBox Err.Number & " - " & Err.Description, _
vbOKOnly Or vbCritical, _
"EnumerateActiveCalendarFolders"
End Sub
See Enumerate Active Folders in the Calendar View for more information.

How to get info about the new message in my secondary mail account?

There are several mail accounts in outlook.
There is a code, that generates a message box with the properties of the new mail in the primary mailbox. It works for my primary mail account.
Option Explicit
Private WithEvents inboxItems As Outlook.Items
Private Sub Application_Startup()
Dim outlookApp As Outlook.Application
Dim objectNS As Outlook.NameSpace
Set outlookApp = Outlook.Application
Set objectNS = outlookApp.GetNamespace("MAPI")
Set inboxItems = objectNS.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub inboxItems_ItemAdd(ByVal Item As Object)
On Error GoTo ErrorHandler
Dim Msg As Outlook.MailItem
Dim MessageInfo
Dim Result
If TypeName(Item) = "MailItem" Then
MessageInfo = "" & _
"Sender : " & Item.SenderEmailAddress & vbCrLf & _
"Sent : " & Item.SentOn & vbCrLf & _
"Received : " & Item.ReceivedTime & vbCrLf & _
"Subject : " & Item.Subject & vbCrLf & _
"Size : " & Item.Size & vbCrLf & _
"Message Body : " & vbCrLf & Item.Body
Result = MsgBox(MessageInfo, vbOKOnly, "New Message Received")
End If
ExitNewItem:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ExitNewItem
End Sub
Here is what the pop-up message looks like:
There is another mailbox "Specification Estimation RU41". My task is to get the same pop-up message for new incoming mail to this mailbox.
I replaced the line
Set inboxItems = objectNS.GetDefaultFolder(olFolderInbox).Items
with
Set inboxItems = objectNS.Folders("Specification Estimation RU41") _
.Folders("Inbox").Items
so that whole code looks like this:
Option Explicit
Private WithEvents inboxItems As Outlook.Items
Private Sub Application_Startup()
Dim outlookApp As Outlook.Application
Dim objectNS As Outlook.NameSpace
Set outlookApp = Outlook.Application
Set objectNS = outlookApp.GetNamespace("MAPI")
Set inboxItems = objectNS.Folders("Specification Estimation RU41") _
.Folders("Inbox").Items
End Sub
Private Sub inboxItems_ItemAdd(ByVal Item As Object)
On Error GoTo ErrorHandler
Dim Msg As Outlook.MailItem
Dim MessageInfo
Dim Result
If TypeName(Item) = "MailItem" Then
MessageInfo = "" & _
"Sender : " & Item.SenderEmailAddress & vbCrLf & _
"Sent : " & Item.SentOn & vbCrLf & _
"Received : " & Item.ReceivedTime & vbCrLf & _
"Subject : " & Item.Subject & vbCrLf & _
"Size : " & Item.Size & vbCrLf & _
"Message Body : " & vbCrLf & Item.Body
Result = MsgBox(MessageInfo, vbOKOnly, "New Message Received")
End If
ExitNewItem:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ExitNewItem
End Sub
But this doesn't work. No error messages, but no reaction at the new mails.
How can I make it work?
Have you tried working with NameSpace.GetSharedDefaultFolder method (Outlook) MSDN
This method is used in a delegation scenario, where one user has delegated access to another user for one or more of their default folders
Example
Private WithEvents RU41_Items As Outlook.Items
Private Sub Application_Startup()
Dim olNs As Outlook.NameSpace
Set olNs = Application.GetNamespace("MAPI")
Dim RU41_Recip As Outlook.Recipient
Set RU41_Recip = olNs.CreateRecipient("0m3r#email.com")
Dim RU41_Inbox As Outlook.MAPIFolder
Set RU41_Inbox = olNs.GetSharedDefaultFolder(RU41_Recip, olFolderInbox)
Set RU41_Items = RU41_Inbox.Items
End Sub
Private Sub RU41_Items_ItemAdd(ByVal Item As Object)
If TypeOf Item Is Outlook.MailItem Then
DoEvents
'''code here
End If
End Sub

Loop through outlook unread emails not working

I am having trouble getting this loop to work. Any advice?
Sub SaveEmailAttachmentsToFolder(OutlookFolderInInbox As String, _
ExtString As String, DestFolder As String)
Dim ns As NameSpace
Dim Inbox As MAPIFolder
Dim SubFolder As MAPIFolder
Dim Item As Object
Dim Atmt As Attachment
Dim FileName As String
Dim MyDocPath As String
Dim i As Integer
Dim wsh As Object
Dim fs As Object
Dim InboxMsg As Object
On Error GoTo ThisMacro_err
Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
Set SubFolder = Inbox.Folders(OutlookFolderInInbox)
'To fix my issue I may have to change the loop to repeat the same number of
times as attachments
' Check subfolder for messages and exit of none found
' strFilter = "[Unread] = True"
' Set inboxItems =
ns.GetDefaultFolder(olFolderInbox).Folders(OutlookFolderInInbox).Items.Restrict(strFilter)
If SubFolder.UnReadItemCount = 0 Then
MsgBox "There are no New messages in this folder : " &
OutlookFolderInInbox, _
vbInformation, "Nothing Found"
Set SubFolder = Nothing
Set Inbox = Nothing
Set ns = Nothing
Exit Sub
End If
'Create DestFolder if DestFolder = ""
If DestFolder = "" Then
Set wsh = CreateObject("WScript.Shell")
Set fs = CreateObject("Scripting.FileSystemObject")
MyDocPath = wsh.SpecialFolders.Item("mydocuments")
DestFolder = MyDocPath & "\" & Format(Now, "dd-mmm-yyyy hh-mm-ss")
If Not fs.FolderExists(DestFolder) Then
fs.CreateFolder DestFolder
End If
End If
If Right(DestFolder, 1) <> "\" Then
DestFolder = DestFolder & "\"
End If
' Check each message for attachments and extensions
strFilter = "[Unread] = True"
Set inboxItems =
ns.GetDefaultFolder(olFolderInbox).Folders(OutlookFolderInInbox).Items.Restrict(strFilter)
' For Each Item In inboxItems
For i = inboxItems.Count To 1 Step -1 'Iterates from the end backwards
Set InboxMsg = Inbox.Items(i)
'For Each Item In inboxItems
' For Each Atmt In inboxItems(I).Attachments
For Each Atmt In InboxMsg.Attachments
If LCase(Right(Atmt.FileName, Len(ExtString))) = LCase(ExtString)
Then
FileName = DestFolder & Format(Item.ReceivedTime, "yyyy-mmm-dd") & Atmt.FileName
Atmt.SaveAsFile FileName
End If
Item.UnRead = "False"
' inboxItems(I).UnRead = "False"
Next Atmt
' Item.UnRead = "false"
Next
' Show this message when Finished
If i = 0 Then
MsgBox "You can find the files here : " _
& DestFolder, vbInformation, "Finished!"
Else
MsgBox "No attached files in your mail.", vbInformation, "Finished!"
End If
' Clear memory
ThisMacro_exit:
Set SubFolder = Nothing
Set Inbox = Nothing
Set ns = Nothing
Set fs = Nothing
Set wsh = Nothing
Exit Sub
' Error information
ThisMacro_err:
MsgBox "An unexpected error has occurred." _
& vbCrLf & "Please note and report the following information." _
& vbCrLf & "Macro Name: SaveEmailAttachmentsToFolder" _
& vbCrLf & "Error Number: " & Err.Number _
& vbCrLf & "Error Description: " & Err.Description _
, vbCritical, "Error!"
Resume ThisMacro_exit
End Sub
Here is Quick example, set filter for both UnRead & Items with Attachments
Option Explicit
Public Sub Example()
Dim olNs As Outlook.NameSpace
Dim Inbox As Outlook.MAPIFolder
Dim Items As Outlook.Items
Dim i As Long
Dim Filter As String
Set olNs = Application.GetNamespace("MAPI")
Set Inbox = olNs.GetDefaultFolder(olFolderInbox)
Filter = "#SQL=" & Chr(34) & "urn:schemas:httpmail:hasattachment" & _
Chr(34) & "=1 AND " & _
Chr(34) & "urn:schemas:httpmail:read" & _
Chr(34) & "=0"
Set Items = Inbox.Items.Restrict(Filter)
For i = Items.Count To 1 Step -1
Debug.Print Items(i) 'Immediate Window
Next
End Sub

Outputting VBA results to text file in Outlook 2010

I am trying to make the below output into a text file on my desktop. I am very new (as in today) and I found the below script online, I have gotten my head around what each but does however I am struggling to make it output as a text file. I am not sure where the commands should go (beginning middle or end?) to do this. I have found one command but I am getting errors left right and centre. Please help.
Sub CountItemsInMBX()
Dim outapp As Outlook.Application
Set outapp = CreateObject("Outlook.Application")
Dim olns As Outlook.NameSpace
Set olns = outapp.GetNamespace("MAPI")
Debug.Print GetSubFolderCount(olns.GetDefaultFolder(olFolderInbox).Parent)
End Sub
Function GetSubFolderCount(objParentFolder As MAPIFolder) As Long
Dim currentFolders As Folders
Dim fldCurrent As MAPIFolder
Set currentFolders = objParentFolder.Folders
If currentFolders.Count > 0 Then
Set fldCurrent = currentFolders.GetFirst
While Not fldCurrent Is Nothing
TempFolderCount = TempFolderCount + GetSubFolderCount(fldCurrent)
Set fldCurrent = currentFolders.GetNext
Wend
Debug.Print objParentFolder.Name & " - " & objParentFolder.Items.Count
GetSubFolderCount = TempFolderCount + objParentFolder.Items.Count
Else
Debug.Print objParentFolder.Name & " - " & objParentFolder.Items.Count
GetSubFolderCount = objParentFolder.Items.Count
End If
End Function
The following is your code, converted to call a function, passing it a string, that will write to a text file. Change the file path & name to suit your needs.
Personally, I don't like the call method because it is a waste to check if the file exists, etc. for every call. However, since your code had two subroutines that need to write text, I was too lazy to embed the proper code in your code. You could either leave as is (if seldom used), or combine together if desired.
Option Explicit
Sub CountItemsInMBX()
Dim outapp As Outlook.Application
Dim olns As Outlook.NameSpace
Set outapp = CreateObject("Outlook.Application")
Set olns = outapp.GetNamespace("MAPI")
'Debug.Print GetSubFolderCount(olns.GetDefaultFolder(olFolderInbox).Parent)
Write_To_MyLog GetSubFolderCount(olns.GetDefaultFolder(olFolderInbox).Parent)
End Sub
Function GetSubFolderCount(objParentFolder As MAPIFolder) As Long
Dim currentFolders As Folders
Dim fldCurrent As MAPIFolder
Dim TempFolderCount As Integer
Set currentFolders = objParentFolder.Folders
If currentFolders.Count > 0 Then
Set fldCurrent = currentFolders.GetFirst
While Not fldCurrent Is Nothing
TempFolderCount = TempFolderCount + GetSubFolderCount(fldCurrent)
Set fldCurrent = currentFolders.GetNext
Wend
'Debug.Print objParentFolder.Name & " - " & objParentFolder.Items.Count
Write_To_MyLog objParentFolder.Name & " - " & objParentFolder.Items.Count
GetSubFolderCount = TempFolderCount + objParentFolder.Items.Count
Else
'Debug.Print objParentFolder.Name & " - " & objParentFolder.Items.Count
Write_To_MyLog objParentFolder.Name & " - " & objParentFolder.Items.Count
GetSubFolderCount = objParentFolder.Items.Count
End If
End Function
Public Function Write_To_MyLog(sText As String)
Dim oFSO As FileSystemObject
Dim oFile As File
Dim oStream As TextStream
On Error GoTo Error_trap
Set oFSO = New FileSystemObject
If Not oFSO.FileExists("C:\Temp\Outlook_Folders.txt") Then
Set oStream = oFSO.CreateTextFile("C:\Temp\Outlook_Folders.txt")
oStream.WriteLine " "
Else
Set oFile = oFSO.GetFile("C:\Temp\Outlook_Folders.txt")
Set oStream = oFile.OpenAsTextStream(ForAppending, TristateMixed)
End If
oStream.WriteLine sText
oStream.Close
Set oStream = Nothing
Set oFile = Nothing
Set oFSO = Nothing
Early_Exit:
Exit Function
Error_trap:
Dim strError As String
strError = "In subroutine: Write_To_MyLog " & vbCrLf & _
Err.Number & vbCrLf & vbCrLf & Err.Description & vbCrLf & _
"At Line: " & Erl
Err.Source = "Module_Utilities: Write_To_MyLog at Line: " & Erl
MsgBox "Error: " & strError
'Write_To_Log strError ' This is a call to a function that saves the error info to a database table.
Resume Early_Exit
Resume Next
End Function

Apply CommandBars functionality in Outlook 2013

I created macros to automate the creation of new calendar appointments and to edit existing calendar appointments in Outlook 2010.
Since upgrading to Outlook 2013 the macro no longer works. I don't get any error message.
Sub NewCustomAppt()
'objects
Dim objExpl As Outlook.Explorer
Dim objFolder As Outlook.MAPIFolder
Dim objCB As Office.CommandBarButton
'appointment
Dim objAppt As Outlook.AppointmentItem
Dim objApptCustom As Outlook.AppointmentItem
Dim objOutlookAttach As Outlook.Attachment
Dim objNS
Set objNS = Application.GetNamespace("MAPI")
On Error Resume Next
Set objExpl = Application.ActiveExplorer
If Not objExpl Is Nothing Then
Set objFolder = objExpl.CurrentFolder
If objFolder.DefaultItemType = olAppointmentItem Then
Set objCB = objExpl.CommandBars.FindControl(, 1106)
If Not objCB Is Nothing Then
objCB.Execute
Set objAppt = Application.ActiveInspector.CurrentItem
Set objApptCustom =
objFolder.Items.Add("IPM.Appointment.your_custom_class")
Set objSel = objDoc.Windows(1).Selection
With objApptCustom
.Start = objAppt.Start
.End = objAppt.End
objAppt.Location = "Careers Service, Level 6 Livingstone Tower"
objAppt.ReminderSet = True
objAppt.ReminderMinutesBeforeStart = 4320
objAppt.Body = "If you wish to cancel or re-schedule this
appointment please let us know as soon as possible, by telephone:
0141 548 4320 or email: yourcareer#strath.ac.uk." & vbNewLine & _
"" & vbNewLine & _
"Please make sure you are prompt for your appointment, if you are
more than 10 minutes late you will not be seen by the adviser."
& vbNewLine & _
& vbNewLine & _
& vbNewLine & _
"Your Careers Adviser for this appointment is:" & vbNewLine & _
"" & vbNewLine & _
"" & vbNewLine & _
In order to prepare for your appointment with your Careers Adviser
please read through the information attached below"
& vbNewLine & _
"" & vbNewLine & _
"" & vbNewLine & _
"" & vbNewLine & _
"" & vbNewLine & _
"" & vbNewLine & _
"This appointment was created on the " & Date & " at" & " " & Time
& vbNewLine & _
objAppt.Attachments.Add "I:\Admin\Careers\INTERVIEW.DOC
'Add the attachment to the e-mail message.
End With
End If
End If
End If
End Sub
From Microsoft:
Command bars are not used in Outlook 2013. CommandBar functions will fail silently.
Use the IRibbonExtensibility interface in an Outlook 2013 add-in instead of command bars. You can’t customize Inspector ribbons by using VBScript code behind forms.
http://technet.microsoft.com/en-us/library/cc178954%28v=office.15%29.aspx
.FindControl(, 1106) works in 2010 so if there is a silent fail in 2013 switch to ExecuteMso
http://msdn.microsoft.com/en-us/library/ff862419.aspx
Private Sub NewCustomAppt_ExecuteMso()
'objects
Dim objExpl As Outlook.Explorer
Dim objFolder As Outlook.Folder
'appointment
Dim objAppt As Outlook.AppointmentItem
Dim objOutlookAttach As Outlook.attachment
Dim objNS
Set objNS = Application.GetNamespace("MAPI")
Set objExpl = Application.ActiveExplorer
If Not objExpl Is Nothing Then
Set objFolder = objExpl.CurrentFolder
If objFolder.DefaultItemType = olAppointmentItem Then
objExpl.CommandBars.ExecuteMso ("NewAppointment") ' <----
Set objAppt = Application.ActiveInspector.CurrentItem
objAppt.location = "Careers Service, Level 6 Livingstone Tower"
objAppt.ReminderSet = True
objAppt.ReminderMinutesBeforeStart = 4320
objAppt.body = "If you wish to cancel or re-schedule this "
End If
End If
End Sub
The IdMso can be seen if you hover over the command when modifying ribbons or the QAT.