Help Please!!! Outlook 2016 - VBA Macro for replying with attachment in meeting invite

Status
Not open for further replies.

JaCrispy

New Member
Outlook version
Outlook 2016 64 bit
Email Account
Office 365 Exchange
Hello,

So I have VBA code to reply to a normal email with attachment, but I need help to modify the code below so that it can also work when you reply from a meeting invitation using email to include the attachments that are included in that meeting invite. If you use the "forward" option from a meeting invite, it forwards the actual meeting invitation, which is not what I would like to do. I would like to reply to the meeting invite and include the attachments.

Code:
Sub ReplyWithAttachments()
    Dim rpl As Outlook.MailItem
    Dim itm As Object
    
    Set itm = GetCurrentItem()
    If Not itm Is Nothing Then
        Set rpl = itm.Reply
        CopyAttachments itm, rpl
        rpl.Display
    End If
    
    Set rpl = Nothing
    Set itm = Nothing
End Sub

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

Sub CopyAttachments(objSourceItem, objTargetItem)
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set fldTemp = fso.GetSpecialFolder(2) ' TemporaryFolder
   strPath = fldTemp.Path & "\"
   For Each objAtt In objSourceItem.Attachments
      strFile = strPath & objAtt.FileName
      objAtt.SaveAsFile strFile
      objTargetItem.Attachments.Add strFile, , , objAtt.DisplayName
      fso.DeleteFile strFile
   Next

   Set fldTemp = Nothing
   Set fso = Nothing
End Sub

Thanks!
 
Because you don't reply to meetings, Set rpl = itm.Reply won't work. I think you'll need to create a new message - there is a send mail to attendees command but i don't know if it is exposed in the object model. (will look later)

Code:
Set replyMeeting = Application.CreateItem(olMailItem)
  replyMeeting.Body = item.body
  replyMeeting.Subject = "Re: " & item.subject
  replyMeeting.To = item.organizer ' not sure if this is right
  replyMeeting.Display ' use .send to send

if you want to reply to all attendees, see Send an email to attendees who have not responded (it can be tweaked to reply to all)
 
Hello,

Thanks for your tip. I have tried implementing it, but it's not working so far :\
 
Hello,

Thanks for your tip. I have tried implementing it, but it's not working so far :\

Actually.. I did get it working, but the format of the body of the invitation gets stripped out and any pictures etc are missing. any ideas?
 
I'll have to test it.
 
Baby steps...

This works (you need the functions from your macro) - but you need to select all and copy the appt body to the clipboard before running the macro. :(

Code:
Sub ConvertSelectionToAppointment()
' You need the GetCurrentItem Function from
'http://slipstick.me/e8mio

    Dim objMail   As Outlook.AppointmentItem
    Dim objAppt As Outlook.MailItem
  
    ' Add reference to Word library
    ' in VBA Editor, Tools, References
    Dim objInsp As Inspector
    Dim objDoc As Word.Document
    Dim objSel As Word.Selection

    Set objMail = GetCurrentItem()
      
    On Error Resume Next
 
  If Not objMail Is Nothing Then
            Set objInsp = objMail.GetInspector
                Set objDoc = objInsp.WordEditor
                Set objWord = objDoc.Application
                Set objSel = objWord.Selection
        With objSel
           'use wholestory to copy the entire message body
 ''            .WholeStory
  '           .Copy
       End With
 
    End If
    

Set replyMeeting = Application.CreateItem(olMailItem)
    Set objInsp = replyMeeting.GetInspector
    Set objDoc = objInsp.WordEditor
    Set objSel = objDoc.Windows(1).Selection


CopyAttachments objMail, replyMeeting
    objSel.PasteAndFormat (wdFormatOriginalFormatting)

    objSel.Range.InsertParagraphBefore
    objSel.Range.InsertParagraphBefore
 
  replyMeeting.Subject = "Re: " & objMail.Subject
  replyMeeting.To = objMail.Organizer ' not sure if this is right
  replyMeeting.Display ' use .send to send
    
    objMail.Categories = "Appt" & objMail.Categories
    Set objAppt = Nothing
    Set objMail = Nothing
End Sub
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
Nufc1980 Outlook "Please treat this as private label" auto added to some emails - Help. Using Outlook 3
S Outlook 2002- "Send" button has disappeared. Help please. Using Outlook 1
Marc2019 Need help please! Cannot Setup my outlook email account on my Mac Outlook 2011 Using Outlook.com accounts in Outlook 2
L Outlook 2002: HTML Emails Will Not Print: Please Help Using Outlook 0
joflo copy contents from outlook to excell - please help. Using Outlook 4
C Please Help outlook 2013 Using Outlook 1
F Help with Outlook 2007 Macro Please! Using Outlook 4
A outlook error Receiving reported error (0x80040900) please help Using Outlook 4
D Help please my Outlook is frozen Using Outlook 3
H Outlook 2010: Cannot start!, please help me! Using Outlook 3
D Outlook 2007 not working>> Please help tried everything Using Outlook 3
U Need a help please Outlook 2007 crashing Using Outlook 2
B Please help! Outlook, Exchange Server, and Customization BCM (Business Contact Manager) 2
B Please help! Outlook, Exchange Server, and Customization Exchange Server Administration 0
C outlook hotmail connector update killed my outlook - please help!! Using Outlook.com accounts in Outlook 3
R i want notifier in outlook express , please help how can i get ? Outlook VBA and Custom Forms 1
V Outlook macro help please Outlook VBA and Custom Forms 23
S.Champ Please help? I've imported a random workcalendar I dont even know who's. Can I undo it? and then I need to re-sync the google one again. Its a mess:( Using Outlook 2
R Disable conversation thread from replying of recipients in the same subject. Please help Using Outlook 0
L Attachment saving and tracking - PLEASE help! Outlook VBA and Custom Forms 5
S VBA Macro - Run-time error '424': object required - Help Please Outlook VBA and Custom Forms 3
A Help with VBA please! Outlook VBA and Custom Forms 15
Denis Hi everyone!!! Need some help with Excel to Exchange Calendar??PLEASE>>> Using Outlook 1
V Please help if you can. Problems with Bcc BCM (Business Contact Manager) 3
J Please help to clarify an IMAP issue Using Outlook 7
M Address book doesn't update contacts? Please any help would be great! Exchange Server Administration 4
N Please help....winmail.dat issue...slowly going insane..... Using Outlook 1
A help please -Boolean - can I use .AND NOT etc in a rule Exchange Server Administration 0
A Advanced find query facilty Help please Using Outlook 2
C Can't import distribution list - help, please Using Outlook 1
V [duplicates duplicates duplicates] please help Using Outlook 26
I can't view email body please help! Using Outlook 6
R VBA Macro to VBScript in a form- Help Please! Using Outlook 10
S Please help! -- Linked Account field at Business Contacts tab is always empty BCM (Business Contact Manager) 1
M Updates to exchange server broke code - please help Using Outlook 2
K shared inbox help please Using Outlook 0
P Please Help me Create a Macro ! Using Outlook 2
J Help please Using Outlook 30
D A little bit of help with headers please? Exchange Server Administration 1
L PLEASE HELP: reconnect existing PST file to imap account Using Outlook 5
L PLEASE HELP: reconnect existing PST file to imap account Using Outlook 1
D Please help. My live.edu mail will not sync. Using Outlook.com accounts in Outlook 1
M Help with shared BCM file please BCM (Business Contact Manager) 5
R SQL Server Setup failed - Please help?! BCM (Business Contact Manager) 2
L Please help an idiot with BCM & Networking... BCM (Business Contact Manager) 5
V Import multiple vCard files!!!!!!! PLEASE HELP Using Outlook 2
S Custom Contact card - need help creating one Outlook VBA and Custom Forms 1
D Lifelong Windows user - new to Mac - Help!!! Using Outlook 3
L Help: set flag for sent mail to check if received an answer Outlook VBA and Custom Forms 2
I Help with Smart Folder + Query Builder on IMAP Using Outlook 0

Similar threads

Back
Top