Results 1 to 5 of 5

Thread: How to get AutoText-value into a mail

  1. #1
    VBAX Newbie
    Jul 2023

    How to get AutoText-value into a mail

    I use VBA to put text in an email.
    When starting the template, the user gets a dialog in which a variable is selected.
    For example: Invoice1
    This variable is the same-value as the name of an AutoText.

    How to put the value of the selected Autotext, with VBA, into the Outlook mail?

    (The Autotext is included in: C:\Users\<user>\AppData\Roaming\Microsoft\Templates\NormalEmail.dotm)

  2. #2
    Moderator VBAX Guru Aussiebear's Avatar
    Dec 2005
    Welcome to VBAX HansFrap. It's very late at night here, and I'm struggling to understand your request.

    When starting the template, the User gets a dialog in which a variable is selected. For Example: Invoice 1. This variable is the same value as the name of an Auto Text
    My first impression is that this is not good coding practice. Maybe I'm just too tired and am not reading this correctly. Secondly where does the Auto text need to reside within the email?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    VBAX Newbie
    Jul 2023
    Aussiebear: Thanks for your answer. Hope this gives extra info.

    On launch, user gets a dialog.
    Here he can choose from invoice for customer 1, 2, etc.
    There are car texts in the template.
    I can put text in mail if I can attach the value of the autotext value to a variable

    Public Sub AddTekst(Tekst As String)
    Dim Inspector As Outlook.Inspector
    Dim wdDoc As Word.Document
    Dim Selection As Word.Selection
        Set Inspector = Application.ActiveInspector()
        Set wdDoc = Inspector.WordEditor
        Set Selection = wdDoc.Application.Selection
            Selection.InsertAfter Tekst
        Set Inspector = Nothing
        Set wdDoc = Nothing
        Set Selection = Nothing
    End Sub

  4. #4
    It is easy enough to write text into a message using VBA, but inserting Autotext is an altogether different problem. Frankly I have not come across a solution to this issue.
    If I was faced with this issue, I would do it in one of two ways.
    1. Create separate Outlook templates as required. You can undoubtedly use your autotexts to create messages which you can then save as templates. Then create messages using the appropriate templates as selected from your dialog.
    Set olItem = CreateItemFromTemplate("C:\Path\TemplateName.oft")
    2. I would create the messages as Word documents, using your autotexts which are much simpler to insert in Word documents, then send the documents as messages to Outlook.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes

  5. #5
    VBAX Newbie
    Jul 2023
    Gmayar, thanks for the suggestions.
    Last week I had already started working with multiple templates. (same idea!)
    I modified design and now I ask the user first to select a customer and then the selected customer template is launched. ☺️

Posting Permissions

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