PDA

View Full Version : Solved: Outlook VBA - Sent Email



eight17
08-09-2012, 10:56 AM
Hello,

I've been searching for this for quite some time now and simply cannot figure this out. :banghead: I'm hoping someone here can point me in the right direction.

Scenario: I send some emails. These emails now show in my "Sent Items" folder. After some time I realize I haven't received a response from some of the recipients. So, I go to my "Sent Items" folder to locate the original email/emails. At this point I'd like to hit "Reply" (so the subject line has the "RE:" and a copy of the original message is in the email body) and instead of my email showing in the "To" field I would need the original recipients email to be listed.

This is simple enough to do manually for a handful of emails... but not realistic for a larger number of emails. Does anyone have a VBA solution that would do what I have described?

I'm open to any ideas/suggestions...

Thanks!

BrianMH
08-10-2012, 09:07 AM
Do you plan on highlighting each mail, do you have some criteria for the sent items folder or are you planning on moving these to a seperate folder and processing them all?

eight17
08-10-2012, 09:20 AM
Hi Brian,

I plan to move all of the emails in question to a separate folder for processing...

BrianMH
08-10-2012, 09:50 AM
Select the folder in outlook and run this code.

Function sendreply()

Dim olApp As Outlook.Application
Dim expl As Outlook.Explorer
Dim currentItems As Outlook.Items

Dim myItem As MailItem
Dim replyItem As MailItem



Set olApp = Outlook.Application
Set expl = olApp.ActiveExplorer
Set currentItems = expl.CurrentFolder.Items
For Each myItem In currentItems
Set replyItem = myItem.Reply
replyItem.To = myItem.To
replyItem.Display

Next
End Function

eight17
08-10-2012, 10:46 AM
This is perfect! Thank you for taking the time to help with this!!

Would you know how I could add a line that would auto-insert a string of text at the top of the message? I tried to add:

replyItem.Body = "test"
But this clears the entire email message and replaces it with "test." Predictable, right? So, I'd like to have it add to the top of the message and not replace the entire message. Any thoughts?

Thanks again!

BrianMH
08-10-2012, 10:54 AM
Try adding

replyitem.body = "Test <BR><BR>" & myitem.body

assuming that the body is html that should do test and two carriage returns. You will need to do that differently based on the type of email formatting it is.

eight17
08-10-2012, 01:15 PM
Thank you for the feedback, Brian. When I use this code:

Function sendreply()

Dim olApp As Outlook.Application
Dim expl As Outlook.Explorer
Dim currentItems As Outlook.Items

Dim myItem As MailItem
Dim replyItem As MailItem

Set olApp = Outlook.Application
Set expl = olApp.ActiveExplorer
Set currentItems = expl.CurrentFolder.Items
For Each myItem In currentItems
Set replyItem = myItem.Reply
replyItem.To = myItem.To
replyItem.HTMLBody = "Test" & myItem.HTMLBody
replyItem.Display
Next
End Function

I loose the auto-inserted signature line that you normally get when you hit the "Reply" button... any thoughts?

Thanks again.

BrianMH
08-10-2012, 01:35 PM
You could add that too the body code. I believe you can just right click in the email and insert your signature. That is pretty quick. There may be a way to insert the signature from your signature files but I don't know how off the top of my head and I don't have office here at home to look at the documentation. I'm off of work for a week now.

You could look at http://stackoverflow.com/questions/8994116/how-to-add-default-signature-in-outlook and see if you can put that into your code.

eight17
08-11-2012, 09:40 AM
Thanks for the link... I'll certainly do what I can. I have very (extremely) limited knowledge of VBA so it should be an interesting process. I'll let you know what I turn up with.

If anyone else has any thought or suggestions I'd be grateful to hear of them!

Thanks again!