I had two questions this week that were similar. In one, the user wanted to decline a meeting but keep a copy of the appointment, the other user wanted to forward accepted meeting to another mailbox.
While these requests don't sound all that similar, the same basic VBA code can be used for both. With one request, we need to copy the fields to a new appointment then decline the meeting, the other one is forwarded then accepted. You can use the basics of these macros to do other things with incoming meeting requests.
Both macros need the GetCurrentItem function listed at the end of this page. This allows you to either select a meeting request in the message list in your inbox or open it to accept or decline.
Rather than using the Accept or Decline buttons, you need to use the macro to accept or decline the meeting then "do whatever". You can add the macro to a button on your QAT, ribbon, or toolbar.
Accept and Forward a Meeting
Don't forget to also add the GetCurrentItem (at the end of this page) to Outlook's VBA editor.
Sub AcceptandForward() Dim oAppt As MeetingItem Dim cAppt As AppointmentItem Dim oRequest As MeetingItem Dim oResponse Set cAppt = GetCurrentItem.GetAssociatedAppointment(True) Set oRequest = GetCurrentItem() Set oAppt = oRequest.Forward oAppt.Recipients.Add "firstname.lastname@example.org" oAppt.Send Set oResponse = cAppt.Respond(olMeetingAccepted, True) oResponse.Send Set cAppt = Nothing Set oAppt = Nothing Set oRequest = Nothing End Sub
Decline and keep a copy of the meeting
Don't forget to also add the GetCurrentItem (at the end of this page) to Outlook's VBA editor.
Sub SaveAndDecline() Dim oAppt As AppointmentItem Dim cAppt As AppointmentItem Dim oResponse Set cAppt = GetCurrentItem.GetAssociatedAppointment(True) Set oAppt = Application.CreateItem(olAppointmentItem) With oAppt .Subject = "Declined: " & cAppt.Subject .Start = cAppt.Start .Duration = cAppt.Duration .Location = cAppt.Location .Save End With Set oResponse = cAppt.Respond(olMeetingDeclined, True) oResponse.Send Set cAppt = Nothing Set oAppt = Nothing End Sub
Accept and Move the Invite
When you accept a meeting, the invitation is moved to the deleted items folder. Moving it to another folder is just 4 added lines. Use the macro at the top of the page and add these lines, with oRequest.Move after the Send (or Display) line.
The folder needs to exist at the same level as the Inbox. If you want to move it to subfolder, use Session.GetDefaultFolder(olFolderInbox).Folders("SharedCal"); to use a folder outside of the current data file, see Working with VBA and non-default Outlook Folders.
' add to top section Dim myFolder As Outlook.folder ' add after Dim section Set myFolder = Session.GetDefaultFolder(olFolderInbox).Parent.Folders("Accepted Invites") oResponse.Send oRequest.Move myFolder 'last line before end sub Set myFolder = Nothing
Accept and Forward a Copy to Another Address
When Exchange server users forward a meeting request, the organizer may be notified the meeting was forwarded. The organizer or administrator can disable this feature, but if you aren't sure if it's disabled and want to avoid generating the notification, you can use a macro to generate a new meeting request and forward it to the address.
This should only be used to forward meetings to your personal account, not to forward the meeting information to other users.
Sub AcceptAndForward() Dim oAppt As AppointmentItem Dim cAppt As AppointmentItem Dim meAttendee As Outlook.Recipient Dim oResponse Set cAppt = GetCurrentItem.GetAssociatedAppointment(True) Set oAppt = Application.CreateItem(olAppointmentItem) With oAppt .MeetingStatus = olMeeting .Subject = "Accepted: " & cAppt.Subject .Start = cAppt.Start .Duration = cAppt.Duration .Location = cAppt.Location Set meAttendee = .Recipients.Add("email@example.com") meAttendee.Type = olRequired .Send End With Set oResponse = cAppt.Respond(olMeetingAccepted, True) oResponse.Send Set cAppt = Nothing Set oAppt = Nothing End Sub
With either of these macros (and many others on this site), you need to use the GetCurrentItem function if you want to use the macro with either opened items or selected items. You only need to have this once within your VBA project and can use it with as many macros as you want.
Function GetCurrentItem() As Object Dim objApp As Outlook.Application Set objApp = Application On Error Resume Next Select Case TypeName(objApp.ActiveWindow) Case "Explorer" Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1) Case "Inspector" Set GetCurrentItem = objApp.ActiveInspector.CurrentItem End Select Set objApp = Nothing End Function
How to add the macro to Outlook and create a toolbar button
Note: you'll also need to open a meeting request and add a button to it, if you want the macro easily accessible from an opened message.
I'm trying to use the "Accept and Forward a Copy to Another Address" on Outlook 2016 and it seems to work with my gmail account. Only thing is that it doesn't delete the meeting invite in my inbox like the normal "Accept" does.
I know that you answered someone with a similar issue in the comments but I think this was back in 2015/2016.
Could you let me know what needs to be done to the "Accept and Forward a Copy to Another Address" vba to delete the meeting invite please?
Could it be that it doesn't work with MS Office Professional Plus 2013 in combination with exchange server? I get an error message. It says: "The operation failed. The message interfaces have returned an unknown error. Cannot resolve recipient" When I debug I see a yellow arrow at the line .Send
it works with exchange - at least in cached mode. Are you using classic online or cached?
I'll see if i can repro that error - it sounds like it is not connecting to the address book.
I guess I use the cached one. In the company we use outlook from the Office package. It is installed on all the laptops.
Which macro are you using?
Does the address its being sent to have single quotes or other characters around the email address?
I used the Sub AcceptandForward()
And I replaced firstname.lastname@example.org for my mailaddress
I have used Accept and Forward a Copy to Another Address. The macro runs without problems if I cut and paste the text from the macro as it is on this page (with the address "email@example.com"). It is when I replace the firstname.lastname@example.org mail address for my own outlook.com or gmail.com address when the error occurs.
What is the error message?
I have tried a few things. The macro works fine when I leave out the dot between my first name and last name in the first part of the email address. So "firstnamelastname@....." works fine, but "firstname.lstname....." doesn't. Unfortunately, my mail address is the one with the dot in it. Also, when the macro has run, the invitation email is still in the inbox.
So this line: oAppt.Recipients.Add "email@example.com"
when the alias had a got in it, fails?
There is no reason why it shouldn't work as long as the address is in quotes but I will see if i can repro.
GetCurrentItem only seems to work with selected meeting invite (email) item and not with a selected meeting item in calendar view. How could this be achieved?
Set cAppt = GetCurrentItem.GetAssociatedAppointment(True) is looking for the appointment associated with the appointment, not the appointment itself. Application.ActiveExplorer.Selection.Item(1) applies to the selected item.
FWIW, it's recommended to accept or decline from the email, not from your calendar - accepting from the calendar doesn't delete the matching email.
I am using Script 3 to Accept the appointment to my Calendar and then send a
copy to a shared team calendar. The original MeetingItem is left in my inbox.
I attempted to use the oRequest.Delete line but I don't believe oRequest is
defined in that example.
I am a total noob at this and am learning a lot through this site and googling but
I have reached the point where I am just guessing now.
Dim oAppt As AppointmentItem
Dim cAppt As AppointmentItem
Dim meAttendee As Outlook.Recipient
Dim oRequest As Outlook.MeetingItem
Set cAppt = GetCurrentItem.GetAssociatedAppointment(True)
Set oAppt = Application.CreateItem(olAppointmentItem)
.MeetingStatus = olMeeting
.Subject = cAppt.Subject
.Start = cAppt.Start
.Duration = cAppt.Duration
.Location = cAppt.Location
Set meAttendee = .Recipients.Add("email address removed")
meAttendee.Type = olRequired
Set oResponse = cAppt.Respond(olMeetingAccepted, True)
Set oRequest = MeetingItem.Delete(olMeetingAccepted, True)
Set cAppt = Nothing
Set oAppt = Nothing
Set oRequest = Nothing
At the top, either right before or right after Set cAppt, add this line:
Set oRequest = GetCurrentItem()
(and use the GetCurrentItem function)
The Accept and Forward Copy is working for me but it creates a duplicate appointment. How do I prevent this from happening?
Thanks for the code for declining and saving!
What would be the line to be added, for the status to show as available?
I tried .MeetingStatus = 1 and others without success
Note: I also added .ReminderSet = False which seems to make sense
Keep getting an error run time error 438 : object doesn't support property or method
Little help with a tweak, please.
I want to decline a meeting but be able to easily change the response later. I tried Save & Decline, but it creates a copy. Can I Decline and Save the original to my Calendar as Free?
As my schedule changes, this would allow me to easily change my response from the event and inform the organizer of my change in status.
I am not aware of any way that will allow you to decline and keep the cancelled appointment, sorry. Tentative was intended for situations like this where you aren't sure if you can attend.
Thank you so much for the quick reply. The scenario is not quite as you mention, however. Frequently I decline meetings I have already accepted because a more important event is created. This more important event is then canceled and I want to rejoin the original meeting. It is never tentative at all, you see.
However, in terms of "logic" what I would like to do is to suppress the deletion of an event not from the invite, but from the appointment itself. So would it be possible to create a Macro that would send the decline message to the organizer, but not perform the delete activity? If this is possible, then I'd add in the script to set Free/Busy as "Free".
Does that clarify or add any thoughts on possibilities?
Thank you so much.