Change the status of an email to 'replied to' using a macro.

I have used the code below which was posted by BlueDevil for auto replying to selecte emails and it works great.  However, I need some additional code which will reply to the email (code below works well) and then will change the status of the email to 'replied to'.  At present the code works, but I have no way of knowing which emails have received a reply and which ones haven't.  Any urgent assistance that can be given I would be grateful.  Here's what I have so far from BlueDevil:

Sub SendCannedResponse()
    Dim olSelection As Outlook.Selection, _
        olResponse As Outlook.MailItem, _
        olReply As Outlook.MailItem, _
        objItem As Object
    Set olSelection = Application.ActiveExplorer.Selection
    For Each objItem In olSelection
        If objItem.Class = olMail Then
            Set olResponse = Application.CreateItem(olMailItem)
            If Left(Application.Version, 2) = "11" Then 'Outlook 2003
                olResponse.Recipients.Add objItem.SenderEmailAddress
            Else 'Some version of Outlook prior to 2003
                Set olReply = objItem.Reply
                olResponse.Recipients.Add olReply.Recipients.Item(1).Address
                Set olReply = Nothing
            End If
            olResponse.Subject = "CV Received"
            olResponse.Body = "We received your CV and are processing it."
            olResponse.Send
            Set olResponse = Nothing
        End If
    Next
    Set objItem = Nothing
    Set olSelection = Nothing
End Sub
jennywattsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David LeeCommented:
Hi jennywatts,
> I have no way of knowing which emails have received a reply and which
> ones haven't

Sorry, but I don't understand what you're looking for.  Any message that is replied to is automatically marked as having been replied to.  The statement I quoted suggests that what you are really looking for is a means of determining which of your replies have been replied to.  If so, then there is no means of doing that with any certainty.  If not, then I don't understand what you want to accomplish.  Could you explain a bit more?

Cheers!
SeanConnollyCommented:
BDF

Don't be cruel - just give her another macro!  :-)
David LeeCommented:
I'll offer that up as soon as I understand what she's looking to accomplish.
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

jennywattsAuthor Commented:
The problem I am having is that when I use the macro it does send a reply, but the original email does not then get automatically marked as 'replied' (with the little arrow).  Even if I open one email and then run the macro it still isn't showing the email as having been replied to - it just shows as if it were a new email that has not been opened.  I am looking for a way in the macro to force it to change the status:

1.Reply to all the selected emails (this bit works fine).
2.Change the status of the selected/highlighted emails to 'replied'.

I realise that all emails that have been replied to should show automatically as replied, but this isn't happening.

Any urgent help please!
David LeeCommented:
Ok, sorry for my confusion.  Try this macro instead.

Sub SendCannedResponse()
    Dim olSelection As Outlook.Selection, _
        olResponse As Outlook.MailItem, _
        objItem As Object
    Set olSelection = Application.ActiveExplorer.Selection
    For Each objItem In olSelection
        If objItem.Class = olMail Then
            Set olResponse = objItem.Reply
            olResponse.Subject = "CV Received"
            olResponse.Body = "We received your CV and are processing it."
            olResponse.Send
            Set olResponse = Nothing
        End If
    Next
    Set objItem = Nothing
    Set olSelection = Nothing
End Sub
jennywattsAuthor Commented:
Hi,

That's exactly what I needed - perfect - thanks.  Just one more thing - I think this is fairly straightfoward and it has just occurred to me?  Could the code be extended to delete the emails that have been sent by the macro which will be stored in the sent items (there will be a rather large volume of these being sent and I am a bit worried that the user will clog up their sent items folder).
David LeeCommented:
No problem.  Replace the alst version with the one below.  It sets the sent item folder to Deleted Items for all messages this macro responds to.

Sub SendCannedResponse()
    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 = "CV Received"
            olResponse.Body = "We received your CV and are processing it."
            Set olResponse.SaveSentMessageFolder = objTrash
            olResponse.Send
            Set olResponse = Nothing
        End If
    Next
    Set objItem = Nothing
    Set olSelection = Nothing
    Set objTrash = Nothing
End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jennywattsAuthor Commented:
Excellent - it worked exactly the way I needed it to.  Thanks BlueDevilFan
David LeeCommented:
You're welcome.
jennywattsAuthor Commented:
Help again please!!!
I am using the code above an it is working fine on my personal mailbox, but I need to use this on another mailbox which has been locked out by Exchange server from sending messages.  When I try to run the macro I am getting a System Administrator Undeliverable message.  What I really need to do is use this macro (send a standard email, mark the original email with 'replied' and have the email sent from me (or whoever is using the macro).  Then I need the macro to delete from my Sent Items (or whoever is sending the mail Sent Items).
Urgent please as I needed to have this finished by this morning.

Thanks
David LeeCommented:
jennywatts,

> When I try to run the macro I am getting a System Administrator Undeliverable message.
I expect that's because the message you are replying to is in a mailbox that has been locked out by the Exchange server.  You can only reply to messages that are in your folders.  If you have been delegated access to another mailbox and reply to a message in it, then you are replying on behalf of the other mailbox owner.  In other words, you are using their account to reply, not your own.  There's no way I know of to get around that.

> What I really need to do is use this macro (send a standard email, mark the original email with 'replied' and have the email sent from me (or whoever is using the macro).  
As I noted above, I don't know of any way to do this if you are replying to a message in a mailbox you are accessing through delegation.

Assuming that I've understood correctly, then I'm sorry, but I don't know of any way to do this.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Outlook

From novice to tech pro — start learning today.