PDA

View Full Version : [SOLVED:] How to get AutoText-value into a mail



HansFrap
07-13-2023, 06:33 AM
Description
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.

Question
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)

Aussiebear
07-13-2023, 07:50 AM
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?

HansFrap
07-13-2023, 08:42 AM
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

gmayor
07-14-2023, 08:32 AM
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.

HansFrap
07-16-2023, 03:34 AM
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. ☺️