Results 1 to 2 of 2

Populate an Outlook e-mail template

  1. #1
    jcc285 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Aug 2014
    Posts
    64

    Populate an Outlook e-mail template

    Is it possible to open an Outlook template file (.oft) and then populate the To, Subject and Body using vba.



    I have the following code

    Private Sub CreateEMail()
    Dim oApp As New Outlook.Application
    Dim oEmail As Outlook.MailItem


    Set oEmail = oApp.CreateItemFromTemplate("C:\Outlook Templates\Template.oft")
    'oEmail.To = "anaddress@gmail.com"
    'oEmail.Subject = "Testing using the template"
    'oEmail.HTMLBody = "Testing where this appears in the template"
    ' in reality these would be text items from a form e.g. me.txtbody.value


    oEmail.Display


    End Sub


    With the .To, .Subject and .HTMLBody commented out the Outlook template file opens correctly

    With those code lines un-commented the template is ignored and a 'standard' Outlook window opens correctly filled in.

    My template has Corporate details in the Body(Message) section and a disclaimer notice to appear at the bottom of the e-mail.

    A secondary question then arises, which is, if it is possible to pass the .HTMLBody item in code, is it possible to control where it appears in the email message.

    I am imagining something like 'fields' in the template into which I pass the required text items much like one would do a mail merge in Word.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    48,365
    See Option 2 in https://www.datanumen.com/blogs/2-qu...e-outlook-vba/

    Your code does not show setting oApp variable. You try to do it in Dim statement. Possibly that is not working as expected. I have never done that way.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Using Outlook Template
    By sovereign in forum Access
    Replies: 2
    Last Post: 08-24-2015, 08:27 AM
  2. Replies: 2
    Last Post: 02-23-2012, 07:21 PM
  3. Replies: 1
    Last Post: 05-20-2011, 07:42 AM
  4. Open Outlook & populate e-mail
    By NISMOJim in forum Forms
    Replies: 7
    Last Post: 10-09-2010, 01:01 PM
  5. usings a outlook template
    By kylebmorris in forum Programming
    Replies: 0
    Last Post: 07-19-2010, 01:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Tech Forums: Microsoft Office Forums