PDA

View Full Version : Sending an eMail from Word



Geoff
08-11-2013, 04:39 AM
I have written a VBa template which is in use by people with various versions of Word to create fairly complex documents. The document is then sent out, and a new one started.

This bit might not be best way of doing what it does, but it works:

With Application.ActiveDocument.MailEnvelope
With .Item
.Recipients.Add = txtOrderEmail
.Subject = txtSubject.Text
.send
End With
End With

The only problem is that each time it is used (in a session - ie the document is sent, then cleared for a new one to start) the contents of txtOrderEmail is added to the recipients list, which usually results in the same addressee being added multiple times.


I can explain why this is the best way I have found doing all this in this particular context if you want :-) Of course, it might not be the best way but it does work except for the issue below.


My question, however, is (I hope) simple: how can I reset the contents of ActiveDocument.MailEnvelope.Item.Recipients so that each time the only recipient is the one added by the .Add?

.Clear (which works for routing slips) doesn't work for this.

Any assistance would be appreciated.

Geoff

Doug Robbins
08-11-2013, 10:51 PM
Use


Dim i as Long
With Application.ActiveDocument.MailEnvelope
With .Item
For i = .Recipients.Count to 1 Step - 1
.Recipients(i).Delete
Next i
.Recipients.Add = txtOrderEmail
.Subject = txtSubject.Text
.send
End With
End With