Link to home
Start Free TrialLog in
Avatar of proltdman
proltdman

asked on

Macro to reply messages with the original message attached

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
Avatar of David Lee
David Lee
Flag of United States of America image

Hi proltdman,

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

Cheers!
Avatar of proltdman
proltdman

ASKER

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
------------------------------------------------------------------
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?
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.
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?
yes I did, but It didn't work for me.. so I'll await your response regarding the first macro.
Thanks...
ASKER CERTIFIED SOLUTION
Avatar of David Lee
David Lee
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.!!!

Thanks!  I'll try.