Consulting

Results 1 to 9 of 9

Thread: Solved: Outlook VBA - Sent Email

  1. #1
    VBAX Newbie
    Joined
    Aug 2012
    Posts
    5
    Location

    Exclamation Solved: Outlook VBA - Sent Email

    Hello,

    I've been searching for this for quite some time now and simply cannot figure this out. 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!

  2. #2
    VBAX Mentor
    Joined
    Feb 2009
    Posts
    493
    Location
    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?
    -----------------------------------------
    The more you learn about something the more you know you have much to learn.

  3. #3
    VBAX Newbie
    Joined
    Aug 2012
    Posts
    5
    Location
    Hi Brian,

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

  4. #4
    VBAX Mentor
    Joined
    Feb 2009
    Posts
    493
    Location
    Select the folder in outlook and run this code.
    [vba]
    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

    [/vba]
    -----------------------------------------
    The more you learn about something the more you know you have much to learn.

  5. #5
    VBAX Newbie
    Joined
    Aug 2012
    Posts
    5
    Location
    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:

    [vba]replyItem.Body = "test"[/vba]
    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!

  6. #6
    VBAX Mentor
    Joined
    Feb 2009
    Posts
    493
    Location
    Try adding

    [VBA]replyitem.body = "Test <BR><BR>" & myitem.body[/VBA]

    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.
    -----------------------------------------
    The more you learn about something the more you know you have much to learn.

  7. #7
    VBAX Newbie
    Joined
    Aug 2012
    Posts
    5
    Location
    Thank you for the feedback, Brian. When I use this code:

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

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

    Thanks again.

  8. #8
    VBAX Mentor
    Joined
    Feb 2009
    Posts
    493
    Location
    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/8...ure-in-outlook and see if you can put that into your code.
    -----------------------------------------
    The more you learn about something the more you know you have much to learn.

  9. #9
    VBAX Newbie
    Joined
    Aug 2012
    Posts
    5
    Location
    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!

Posting Permissions

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