Sunday, May 24, 2009

How to Reply to Mail using Outlook VBA

Copy formatted word document to Outlook mail using VBA


Here is a simple snippet that replies to the mail using VBA. The contents of the document has earlier been saved as HTML and the HTML is copied to the mail Item

Public Sub ReplyWithHTML()
Dim oMail As Outlook.MailItem
Dim oFSO
Dim oFS

If Application.ActiveExplorer.Selection.Count Then
If TypeOf Application.ActiveExplorer.Selection(1) Is Outlook.MailItem Then
Set oMail = Application.ActiveExplorer.Selection(1).Reply

Set oFSO = CreateObject("Scripting.FileSystemObject")

Set oFS = oFSO.OpenTextFile("C:\ForBlogger\formedSample.html")


stext = oFS.readall
oMail.BodyFormat = olFormatHTML
oMail.HTMLBody = stext & vbCr & oMail.HTMLBody
oMail.Display
End If
End If
End Sub


4 comments:

  1. Anonymous4:59 AM

    works great, however if my document has jpg files, they are not displayed. Any tricks

    ReplyDelete
  2. yea this is awesome.. how can you then have the replied item moved automatically to a folder.

    ReplyDelete
  3. The code was awesome but I need to reply to more mail in a particular folder.

    ReplyDelete
  4. I don't know if you will see this comment but I have been using this effectively for a long time. Doesn't work in Outlook 2016. Have you discovered the same? Is there a solution?

    ReplyDelete

StumbleUpon
Share on Facebook
Related Posts Plugin for WordPress, Blogger...
Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.