none
Outlook Form to Populate Template RRS feed

  • Question

  • Hi Everyone,

    I would like to create a Outlook Form that has 8 Input Text Boxes that when finished would generate an email using those inputs. 

    EX)

    Template:

    Name,

    Hello, my name is Employee. I would like to talk to you about Property.

    The input boxes would be

    Name:

    Employee:

    Property:

    I want to only have to fill out those 3 fields to auto generate the entire email. 

    Thank you guys!

    Wednesday, September 28, 2016 8:21 PM

Answers

  • Hi,

    Try the following:

    Create a form and three textboxs and a CommandButton

    set ShowModal of the form into False


    Private Sub CommandButton1_Click()
    Dim objMsg As MailItem
    Set objMsg = Application.CreateItem(olMailItem)
    With objMsg
     .BodyFormat = olFormatHTML
     .HTMLBody = "<p>" & TextBox1.Text & ",</p><p>Hello, my name is " & TextBox2.Text _
     & ". I would like to talk to you about " & TextBox3.Text & "</p>"
     .Display
    End With
    End Sub


    • Marked as answer by Oskar Plinski Thursday, September 29, 2016 2:02 PM
    Thursday, September 29, 2016 2:51 AM
    Moderator

All replies

  • Hello Oskar,

    Looks like you need to add a code behind for generating the message body based on the data entered to the text fields. If so, you need to set the message body using a VBScript (what custom forms are based on). See Getting Started with VBA in Outlook 2010 (they are very close to each other).

    The Outlook object model provides three main ways for working with item bodies:

    1. Body - a string representing the clear-text body of the Outlook item.
    2. HTMLBody - a string representing the HTML body of the specified item.
    3. Word editor - the Microsoft Word Document Object Model of the message being displayed. The WordEditor property of the Inspector class returns an instance of the Document class from the Word object model which you can use to set up the message body.

    You can read more about all these ways in the Chapter 17: Working with Item Bodies. It us up to you which way is to choose to set up the message body.


    [custom.development]

    Wednesday, September 28, 2016 8:39 PM
  • Hi,

    Try the following:

    Create a form and three textboxs and a CommandButton

    set ShowModal of the form into False


    Private Sub CommandButton1_Click()
    Dim objMsg As MailItem
    Set objMsg = Application.CreateItem(olMailItem)
    With objMsg
     .BodyFormat = olFormatHTML
     .HTMLBody = "<p>" & TextBox1.Text & ",</p><p>Hello, my name is " & TextBox2.Text _
     & ". I would like to talk to you about " & TextBox3.Text & "</p>"
     .Display
    End With
    End Sub


    • Marked as answer by Oskar Plinski Thursday, September 29, 2016 2:02 PM
    Thursday, September 29, 2016 2:51 AM
    Moderator
  • This is exactly what i was looking for. Thank you!
    Thursday, September 29, 2016 2:02 PM
  • what would i use to make the text from the texbox to show as bold?
    Thursday, September 29, 2016 3:08 PM
  • Hi,

    Add <b></b> to show as bold

    Private Sub CommandButton1_Click()
    Dim objMsg As MailItem
    Set objMsg = Application.CreateItem(olMailItem)
    With objMsg
     .BodyFormat = olFormatHTML
     .HTMLBody = "<p><b>" & TextBox1.Text & "</b>,</p><p>Hello, my name is <b>" & TextBox2.Text _
     & "</b>. I would like to talk to you about <b>" & TextBox3.Text & "</b></p>"
     .Display
    End With
    End Sub

    Thursday, September 29, 2016 3:46 PM
    Moderator