Solved

Macro to reply messages with the original message attached

Posted on 2006-07-13
9
593 Views
Last Modified: 2012-06-21
I am currently using this great code by BlueDevilFan below, it works like a dream but I want to be able to attach the original message at the bottom of my reply.
Can anyone help, its pretty urgent!
Thanks.

here is the current Macro I use in Outlook 2002:

Sub Deduped()

    commtext = "Your records have been de-duped"
    Dim olSelection As Outlook.Selection, _
        olResponse As Outlook.MailItem, _
        objItem As Object, _
        objTrash As MAPIFolder
    Set objTrash = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderDeletedItems)
    Set olSelection = Application.ActiveExplorer.Selection
    For Each objItem In olSelection
        If objItem.Class = olMail Then
            Set olResponse = objItem.Reply
            olResponse.Subject = "De-duped"
            olResponse.Body = commtext
            olResponse.Send
            Set olResponse = Nothing
        End If
    Next
    Set objItem = Nothing
    Set olSelection = Nothing
   
End Sub
0
Comment
Question by:proltdman
  • 5
  • 4
9 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 17101190
Hi proltdman,

Thanks for the generous comment.  Attach the entire message, or cut and paste the content of the original message?

Cheers!
0
 

Author Comment

by:proltdman
ID: 17101303
I would prefer to copy/cut and paste the original message.
However, a solution to both would be brill, that way I can have a choice of two separate macors..!

Meanwhile I tried to implement the attachment macro you also developed for forwarding emails to the secretary's email address with the original message included as an attachment, but I got an error message on the first line...saying "Compile Error: Only valid in Object module". I did download and install Redemption but that did not help.

here's your code that I tried to use.. anyway see what you can do I know you're the man.!!!
-----------------------------------------------------------------
Public WithEvents myOlItems As Outlook.Items

Private Sub Application_Startup()
    Set myOlItems = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub myOlItems_ItemAdd(ByVal Item As Object)
    Dim redMailItem As Object
    Set redMailItem = CreateObject("Redemption.SafeMailItem")
    redMailItem.Item = Item
    'Change AliasEmailAddress on the following line
    If redMailItem.To = "anthonyroberts@proltd.com" Then
        redMailItem.Item = Application.CreateItem(olMailItem)
        'Change the email address on the following line to that of the secretary
        redMailItem.Recipients.Add "anthonyroberts@hydrogengroup.com"
        redMailItem.Recipients.ResolveAll
        redMailItem.Attachments.Add Item, olEmbeddeditem
        'Change the subject on the following line as desired
        redMailItem.Subject = "Redirected Message: " & Item.Subject
        'Change the message body on the following line as desired
        redMailItem.Body = "The message is in the attachment."
        redMailItem.Send
    End If
    Set redMailItem = Nothing
End Sub
------------------------------------------------------------------
0
 
LVL 76

Expert Comment

by:David Lee
ID: 17105117
Ok, let's deal with the first question first.  I looked at the code again and realized it's creating a reply.  Replies include the original message.  Cutting and pasting the original message into the reply would duplicate the original message.  I must be missing something.

Now the second question.  The code has to go into the ThisOutlookSession module.  Are you saying it is in that location and is givng the error you listed?
0
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.

 

Author Comment

by:proltdman
ID: 17107135
I'm afraid the replies only have my pre-defined text "Your records have been de-duped" in them and nothing else. It also flags the messages as replied when the replies are sent which is perfect.
I would like the macro amended to append the original message in the reply. You can either amend it to attach the original message as an attachment or cut/paste to the bottom of my reply, I would prefer the cut/paste solution but as I said before both methods would be brill as that'll give me a choice.

As for the second macro that requires Redemption to work, I have put the macro in the ThisOutlookSession module but it doesn't show up as a macro so how do I use test it?


Thanks once again for your time.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 17107172
Ok, i'll have another look at the first macro.

The second macro isn't designed to be run manually.  It is desigend to run automatically.  Specifically, it's designed to run each time an item arrives in the inbox.  If it's not running automatically, then have you followed the instructions I poseted in the original question?
0
 

Author Comment

by:proltdman
ID: 17107223
yes I did, but It didn't work for me.. so I'll await your response regarding the first macro.
Thanks...
0
 
LVL 76

Accepted Solution

by:
David Lee earned 250 total points
ID: 17109294
Ok, I see the problem and it's this line:

    olResponse.Body = commtext

Replies do include the body of the original message, but this line of code is wiping the body out by replacing it with the contents of the variable commtext.  We just need to change this line to

                olResponse.Body = commtext & vbCrLf & olResponse.Body

This will prepend the contents of commtext to the existing body which already contains the original message.  The vbCrLf throws a new line in between whatever is in commtext and the existing body.
0
 

Author Comment

by:proltdman
ID: 17109472
GREAT WORK! it's working perfectly as I want it.
Once again BDF you've delivered a great solution, I have awarded full points to you for your prompt assistance and exceptional approach to problem solving. You are a valued asset to EE. Keep up the good work.!!!

0
 
LVL 76

Expert Comment

by:David Lee
ID: 17110094
Thanks!  I'll try.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

829 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