Solved

Macro to reply messages with the original message attached

Posted on 2006-07-13
9
579 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:proltdman
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 76

Expert Comment

by:David Lee
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks!  I'll try.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Create high volume marketing opportunities using email signatures with these top 10 DOs and DON'Ts of email signature marketing.
Use email signature images to promote corporate certifications and industry awards.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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: …

771 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

12 Experts available now in Live!

Get 1:1 Help Now