Consulting

Results 1 to 13 of 13

Thread: macro to reply to an email with auto text almost done

  1. #1

    macro to reply to an email with auto text almost done

    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!

  2. #2
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    Please use VBA code tags when posting code.

    If you don't want to delete the emails, remove this line from your code:

    [VBA]mymail.Delete[/VBA]

    To preserve the original subject line in the reply, use:

    [VBA]
    myReply.Subject = mymail.Subject
    [/VBA]
    Regards,
    JP

    Read the FAQ
    Getting free help on the web
    My website
    Please use [vba][/vba] tags when posting code

  3. #3
    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

  4. #4
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    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.
    Regards,
    JP

    Read the FAQ
    Getting free help on the web
    My website
    Please use [vba][/vba] tags when posting code

  5. #5
    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

  6. #6
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    Got it, in that case you need to adjust this line:

    [VBA]myReply.Body = mytext[/VBA]

    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:

    [VBA]myReply.Body = mytext & vbcrlf & mymail.Body[/VBA]
    Regards,
    JP

    Read the FAQ
    Getting free help on the web
    My website
    Please use [vba][/vba] tags when posting code

  7. #7
    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

  8. #8
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    LOL you literally just have to paste

    [vba]myReply.Body = mytext & vbcrlf & mymail.Body[/vba]

    over


    [vba]
    myReply.Body = mytext
    [/vba]

    If you can't do that, you have problems I can't solve.
    Regards,
    JP

    Read the FAQ
    Getting free help on the web
    My website
    Please use [vba][/vba] tags when posting code

  9. #9
    lol that is a good point!! ok i swopped out that line for the one you suggested so it looked like this

    [VBA]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[/VBA]


    but the text on the prevous email was still deleted any ideas or have i just done it wrong

  10. #10
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    Try taking the body text from the original, not the reply. Instead of

    [VBA]mytext = myReply.Body[/VBA]

    use

    [VBA]mytext = mymail.Body[/VBA]
    Regards,
    JP

    Read the FAQ
    Getting free help on the web
    My website
    Please use [vba][/vba] tags when posting code

  11. #11
    tried that and it didnt work either this is what i did

    [VBA]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[/VBA]

  12. #12
    VBAX Regular
    Joined
    Jul 2010
    Posts
    66
    Location
    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:

    [vba]
    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
    [/vba]
    Hope this helps.

    GComyn

  13. #13
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    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:

    [VBA]myText = myMail.Body[/VBA]


    Quote Originally Posted by aftermarket
    tried that and it didnt work either this is what i did
    Regards,
    JP

    Read the FAQ
    Getting free help on the web
    My website
    Please use [vba][/vba] tags when posting code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •