Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Macro to reply messages with the original message attached

Posted on 2006-07-13
9
Medium Priority
?
656 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 1000 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
There can be many situations demanding the conversion of Outlook OST files to PST format and as such, there is no shortage of automated tools to perform this conversion. However, what makes Stellar OST to PST converter stand above the rest? Let us e…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

877 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