View Full Version : macro to reply to an email with auto text almost done
aftermarket
02-03-2011, 06:03 AM
we currently use this:-
Sub When_will_my_item_get()
Dim mymail As Outlook.MailItem
Dim myReply As Outlook.MailItem
Dim numItems As Integer
Set mySelected = Outlook.ActiveExplorer.Selection
numItems = mySelected.Count
For i = 1 To numItems
Set mymail = mySelected(1)
Set myReply = mymail.Reply
mytext = myReply.Body
myReply.Subject = "Response to item tracking"
With myReply
mytext = "Hello," & vbCrLf
mytext = mytext & vbCrLf & "We can confirm that your item has been despatched, you should be receiving it within the next 2 - 5 working business days (excludes Saturday and Sundays). This is on the condition that:- We have received payment from your self - you'll have confirmation by email of this either by pay pal, eBay or our own website email If you paid by cheque or postal order please allow an additional 2 - 5 working days to allow the funds to clear"
mytext = mytext & vbCrLf & "Thank You"
mytext = mytext & vbCrLf & "ams"
mytext = mytext & vbCrLf & "01723 81"
End With
myReply.Body = mytext
myReply.Send
mymail.Delete
Set mymail = Nothing
Set myReply = Nothing
Next
Set mySelected = Nothing
End Sub
however whenever we fire the email off it deletes the whole converstion how would we make it so that the prevous emails are kept at the bottom? also does anyone know how to make the original subject line stay the same without using our subject line
thanks in advance!
JP2112
02-03-2011, 06:47 AM
Please use VBA code tags when posting code.
If you don't want to delete the emails, remove this line from your code:
mymail.Delete
To preserve the original subject line in the reply, use:
myReply.Subject = mymail.Subject
aftermarket
02-03-2011, 06:59 AM
hi, thanks for having a look. in terms of deleting the email i want it deleted within out look what it does is delete the entire email conversation and just sends the auto email could do with it keeping the previous emails within the email if that makes sense
JP2112
02-03-2011, 07:06 AM
I guess I don't understand what you want.
You want the emails deleted, but you don't want the conversation deleted. A "conversation" is just a list of emails (which happen to be related by subject).
If you want the emails deleted, the conversation will be deleted as well, if you've selected the entire conversation before running the code.
If you don't want to delete the conversation, don't delete the emails.
aftermarket
02-04-2011, 03:41 AM
basically how this works now is that i have out look open and the email selected for which i want the auto email to go to. i then hit a button on the tool bar for the correct auto reply. this replys to the email selected then deletes it off my out look. what i need it to do is to do all that but when it sends the email to the customer for it to keep the content of the original email at the bottom of the email so if they reply to us we can then see whats been said before. hope this helps thanks
JP2112
02-04-2011, 08:04 AM
Got it, in that case you need to adjust this line:
myReply.Body = mytext
This line is wiping out all the text that is already in the message. To preserve the existing text of the reply, use this instead:
myReply.Body = mytext & vbcrlf & mymail.Body
aftermarket
02-07-2011, 05:47 AM
hi thanks for that i'm not really clued up enough to code that into the script that i gave you earlier could i be cheeky and ask yourself if you could place the correct bits in i'd be very grateful for this, thank you
JP2112
02-07-2011, 08:32 AM
LOL you literally just have to paste
myReply.Body = mytext & vbcrlf & mymail.Body
over
myReply.Body = mytext
If you can't do that, you have problems I can't solve. :)
aftermarket
02-07-2011, 12:59 PM
lol that is a good point!! ok i swopped out that line for the one you suggested so it looked like this
Sub When_will_my_item_get()
Dim mymail As Outlook.MailItem
Dim myReply As Outlook.MailItem
Dim numItems As Integer
Set mySelected = Outlook.ActiveExplorer.Selection
numItems = mySelected.Count
For i = 1 To numItems
Set mymail = mySelected(1)
Set myReply = mymail.Reply
mytext = myReply.Body
myReply.Subject = "Response to item tracking"
With myReply
mytext = "Hello," & vbCrLf
mytext = mytext & vbCrLf & "We can confirm that your item has been despatched, you should be receiving it within the next 2 - 5 working business days (excludes Saturday and Sundays). This is on the condition that:- We have received payment from your self - you'll have confirmation by email of this either by pay pal, eBay or our own website email If you paid by cheque or postal order please allow an additional 2 - 5 working days to allow the funds to clear"
mytext = mytext & vbCrLf & "Thank You"
mytext = mytext & vbCrLf & "Aftermarketsounds.com Team"
mytext = mytext & vbCrLf & "01723 81 81 35"
End With
myReply.Body = mytext & vbCrLf & mymail.Body
myReply.Send
mymail.Delete
Set mymail = Nothing
Set myReply = Nothing
Next
Set mySelected = Nothing
End Sub
but the text on the prevous email was still deleted :( any ideas or have i just done it wrong
JP2112
02-08-2011, 10:58 AM
Try taking the body text from the original, not the reply. Instead of
mytext = myReply.Body
use
mytext = mymail.Body
aftermarket
02-09-2011, 03:21 AM
tried that and it didnt work either :( this is what i did
Sub When_will_my_item_get()
Dim mymail As Outlook.MailItem
Dim myReply As Outlook.MailItem
Dim numItems As Integer
Set mySelected = Outlook.ActiveExplorer.Selection
numItems = mySelected.Count
For i = 1 To numItems
Set mymail = mySelected(1)
Set myReply = mymail.Reply
mytext = mymail.Body
myReply.Subject = "Response to item tracking"
With myReply
mytext = "Hello," & vbCrLf
mytext = mytext & vbCrLf & "We can confirm that your item has been despatched, you should be receiving it within the next 2 - 5 working business days (excludes Saturday and Sundays). This is on the condition that:- We have received payment from your self - you'll have confirmation by email of this either by pay pal, eBay or our own website email If you paid by cheque or postal order please allow an additional 2 - 5 working days to allow the funds to clear"
mytext = mytext & vbCrLf & "Thank You"
mytext = mytext & vbCrLf & "Aftermarketsounds.com Team"
mytext = mytext & vbCrLf & "01723 81 81 35"
End With
myReply.Body = mytext & vbCrLf & mymail.Body
myReply.Send
mymail.Delete
Set mymail = Nothing
Set myReply = Nothing
Next
Set mySelected = Nothing
End Sub
gcomyn
02-09-2011, 10:06 AM
I'm not sure why you are not getting what you want... I tried out the code and it did exactly what you said you wanted... created an email with the text written at the top, and the body of the email replied to at the bottom.... There were a few things there that weren't needed, so I took them out... Also, for testing purposes, you can use 'myreply.save' and comment out the mymail.delete lines, that way the email is not deleted, and the reply is not sent, just saved in Drafts for you to look at.
Here is the code that I ended up with:
Sub When_will_my_item_get()
Dim myMail As Outlook.MailItem
Dim myReply As Outlook.MailItem
Dim numItems As Integer
Dim mySelected As Selection
Dim i As Integer
Dim myText As String
Stop
Set mySelected = Outlook.ActiveExplorer.Selection
numItems = mySelected.Count
For i = 1 To numItems
Set myMail = mySelected(1)
Set myReply = myMail.Reply
myText = myMail.Body
myReply.Subject = "Response to item tracking"
myText = "Hello," & vbCrLf
myText = myText & vbCrLf & "We can confirm that your item has been despatched, you should be receiving it within the next 2 - 5 working business days (excludes Saturday and Sundays). This is on the condition that:- We have received payment from your self - you'll have confirmation by email of this either by pay pal, eBay or our own website email If you paid by cheque or postal order please allow an additional 2 - 5 working days to allow the funds to clear."
myText = myText & vbCrLf & "Thank You"
myText = myText & vbCrLf & "Aftermarketsounds.com Team"
myText = myText & vbCrLf & "01723 81 81 35"
myText = myText & vbCrLf & "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
myReply.Body = myText & vbCrLf & myMail.Body
myReply.Send
myMail.Delete
Set myMail = Nothing
Set myReply = Nothing
Next
Set mySelected = Nothing
End Sub
Hope this helps.
GComyn
:sleuth:
JP2112
02-10-2011, 01:50 PM
Just tested your code and it works as you described. Try stepping through the code (press F9) and check the value of each variable.
FYI you can take out this line:
myText = myMail.Body
tried that and it didnt work either :( this is what i did
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.