On Tue, 25 Oct 2005 09:57:07 GMT, Susan Bricker <sl*****@verizon.net>
wrote:
I know that it is possible to generate an email letter and send it from
VBA behind a form. I've done that. However, is it possible to create a
DRAFT email letter and leave it in the Drafts folder (in Microsoft
Outlook)? If it is possible, would you share the source code with me?
Public Sub SendMailWithAttachment( _
strTo As String, _
strAttachmentFiles As String, _
Optional strSubject As String = "", _
Optional strBodyText As String = "", _
Optional bolQuitOutlook As Boolean = False, _
Optional bolSendAsDraft As Boolean = True)
Dim OL As Object
Dim OLNS As Object 'Outlook.NameSpace
Dim MailFolder As Object 'Outlook.MAPIFolder
Dim MyMail As Object 'Outlook.MailItem
Dim varAttachments As Variant
Dim I As Integer
varAttachments = Split(strAttachmentFiles, Chr$(0))
Set OL = CreateObject("Outlook.Application")
Set OLNS = OL.GetNamespace("MAPI")
If bolSendAsDraft = True Then
Set MailFolder = OLNS.GetDefaultFolder(16)
Else
Set MailFolder = OLNS.GetDefaultFolder("Inbox")
End If
Set MyMail = MailFolder.Items.Add
With MyMail
.To = strTo
.Subject = strSubject
.Body = strBodyText
For I = 0 To UBound(varAttachments)
If CStr(varAttachments(I)) <> "" Then _
.Attachments.Add CStr(varAttachments(I)), _
1, _
I + 1
Next
.Recipients.ResolveAll
.Save
If bolSendAsDraft = False Then
.Send
End If
End With
If bolQuitOutlook = True Then OL.Quit
Set MyMail = Nothing
Set MailFolder = Nothing
Set OLNS = Nothing
Set OL = Nothing
End Sub
--
Drive C: Error. (A)bort (R)etry (S)mack The Darned Thing