Solved

Outlook VBA for Reply To All with Attachment

Posted on 2009-05-05
15
1,523 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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Resolve DNS query failed errors for Exchange
Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now