Solved

Outlook VBA for Reply To All with Attachment

Posted on 2009-05-05
15
1,586 Views
Last Modified: 2012-05-06
Hi,

I want a Outlook VBA which will be able to do the following:

1) I am selecting a message from my Inbox.
2) I am pressing a shortcut key for the VBA
3) This will do the "Reply to All" and a customized signature will be added as my "Reply". The Attachment (if any) will also automatically addded with the reply.

PLease help me. I am using MS Office outlook 2003.
0
Comment
Question by:suvmitra
  • 8
  • 6
15 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24303004
SOmething like right click on an email and have an option to reply special ... or whatever you want to call it?

Customised signature - with outlook 2003 I don't think the signature can be added 'automatically that easily but it could be hard coded though.

Attachment automatically added - how would that be identified?

Chris
0
 
LVL 17

Expert Comment

by:Shanmuga Sundaram
ID: 24303048
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24303181
Assuming yes then two stages:

One add a sub to a normal code module as below:

Sub replySpecial()
Dim maiNew As Outlook.mailitem
Dim maiOrig As Object
   
    Set maiOrig = Application.ActiveExplorer.Selection.Item(1)
    If Not maiOrig Is Nothing Then
        Set maiNew = maiOrig.reply
        CopyAttachments maiOrig, maiNew
        maiNew.Display
    End If
   
Set maiNew = Nothing
Set maiOrig = Nothing
End Sub

Sub CopyAttachments(objSourceItem, objTargetItem)
' See outlookcode.com
Dim fso As Object
Dim fldTemp As Object
Dim strPath As String
Dim strFile As String
Dim objatt As Object

   Set fso = CreateObject("Scripting.FileSystemObject")
   Set fldTemp = fso.GetSpecialFolder(2) 'Temp
   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

Two add a sub to thisoutlooksession as Application_ItemContextMenuDisplay and paste the body of teh code from teh code in teh snippet therein.

Now when you right click on a mail in the explorer the menu has an option for reply special click and the 'new' mail is displayed for you to send

Chris
Private Sub Application_ItemContextMenuDisplay(ByVal CommandBar As Office.CommandBar, ByVal Selection As Selection)
Const msoControlButton = 1
Const msoButtonIconAndCaption = 3
Dim objButton As CommandBarButton
    If Selection.count = 1 Then
        If Selection.Item(1).Class = olMail Then
            Set objButton = CommandBar.Controls.Add(msoControlButton)
            With objButton
                .Style = msoButtonIconAndCaption
                .Caption = "Reply Special with Attachments"
                .Parameter = Selection.Item(1).EntryID
                'List of face IDs here: http://www.kebabshopblues.co.uk/2007/01/04/visual-studio-2005-tools-for-office-commandbarbutton-faceid-property/'
                .FaceId = 355
                .OnAction = "ReplySpecial"
            End With
        End If
    End If
End Sub

Open in new window

0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 9

Author Comment

by:suvmitra
ID: 24304506
chris_bottomley:
I believe I did exactly as you guided but I am not able to see any "Reply Special with Attachment" option at my outlook context menu. Please suggest. PS. I have restarted the outlook but there is nothing special things are happening.
 
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24304869
In thisoutlooksession click on application and then ItemContextMenuDisplay - make sure the supplied code is therein and that there is only one such sub declaration in the module.

Chris
0
 
LVL 9

Author Comment

by:suvmitra
ID: 24307237
Hi,
My outlook does not have any ItemContextMenuDisplay into the application. I copy and paste the entire code but this is not working. Please suggest.

outlook.JPG
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24307349
I really must get head out from under the pillow!

Okay that is an outlook 2007 feature and I forget how much is new - Sorry.

Next opportunity then is to trigger a modified macro via a button on outlook itself i.e. under tools macro menu or perhaps a button, (not 100% about buttons in OLK2003 but I will try if needed.

Any good?

Chris
0
 
LVL 9

Author Comment

by:suvmitra
ID: 24308792
Can you please do that and test. I need to implement this in outlook 2003 environment. Thank you for your help and effort.
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24308906
Okay the the modified snippet below goes in a code module.

In the outlook interface:

Right click in teh toolbar white space and click customise
On teh commands tab : macros | find reply special and drag it to a toolbar.

Now exit back to the outlook screen and select an email to reply to and use the reply special entry in the relevant menu.

Chris
Sub replySpecial()
Dim maiNew As Outlook.mailitem
Dim maiOrig As Object
    
    If TypeName(Application.ActiveWindow) = "Explorer" Then
        Set maiOrig = Application.ActiveExplorer.Selection.Item(1)
    ElseIf TypeName(Application.ActiveWindow) = "Inspector" Then
            Set maiOrig = Application.ActiveInspector.CurrentItem
    Else
        Exit Sub
    End If
    If Not maiOrig Is Nothing Then
        Set maiNew = maiOrig.reply
        CopyAttachments maiOrig, maiNew
        maiNew.Display
    End If
    
Set maiNew = Nothing
Set maiOrig = Nothing
End Sub
 
Sub CopyAttachments(objSourceItem, objTargetItem)
' See outlookcode.com
Dim fso As Object
Dim fldTemp As Object
Dim strPath As String
Dim strFile As String
Dim objatt As Object
 
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set fldTemp = fso.GetSpecialFolder(2) 'Temp
   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

Open in new window

0
 
LVL 9

Author Comment

by:suvmitra
ID: 24312675
What I can say..this is simply excellent piece of Art. I just want to add to more things:
a) If you look at the picture it is taking the entire refernce as name and it seems too long. How do I rename it say "Reply Special" instead of Project1.Project1.Module2.Pastespecial.
b) I want to populate a generic message with the Reply to All like,
"Hi,
This is the Reply.
Regards,
ABC"

special.JPG
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24312738
a) If you look at the picture it is taking the entire refernce as name and it seems too long. How do I rename it say "Reply Special" instead of Project1.Project1.Module2.Pastespecial.

IN an open area of the menus, click customise now right click the button and you can edit the name in the text field.

b) I want to populate a generic message with the Reply to All like,See replyspecial as updated below

Chris
Sub replySpecial()
Dim maiNew As Outlook.mailitem
Dim maiOrig As Object
    
    If TypeName(Application.ActiveWindow) = "Explorer" Then
        Set maiOrig = Application.ActiveExplorer.Selection.Item(1)
    ElseIf TypeName(Application.ActiveWindow) = "Inspector" Then
            Set maiOrig = Application.ActiveInspector.CurrentItem
    Else
        Exit Sub
    End If
    If Not maiOrig Is Nothing Then
        Set maiNew = maiOrig.reply
        maiNew.body = "Hi, " & vbCrLf & vbCrLf & _
            "This is the Reply." & vbCrLf & vbCrLf & _
            "Regards," & vbCrLf & vbCrLf & _
            "ABC" & _
            maiNew.body
        CopyAttachments maiOrig, maiNew
        maiNew.Display
    End If
    
Set maiNew = Nothing
Set maiOrig = Nothing
End Sub

Open in new window

0
 
LVL 9

Author Comment

by:suvmitra
ID: 24313027

Brilliant!!

Everything is just perfect!

But still I am not able to rename the Macro. I am not getting any right click / context menu option there. Please see the attached.

not.JPG
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 500 total points
ID: 24313129
NO ...

Having launched the customise box, ignore it and move to your button and right click that - on completion of the edit THEN close the customise box

Chris
0
 
LVL 9

Author Closing Comment

by:suvmitra
ID: 31577936
This is Done!! Thank you.
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24313271
Glad to help

Chris
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question