' These object names are the ones I've chosen, and I don't
' think they're by any means the best. Choose ones that
' suit your programming style - and thy're bound to be
' better than these!
Dim objOutlook As New Outlook.Application
Dim objNameSpace As Outlook.NameSpace
Dim objOutBox As MAPIFolder
Dim objMail As MailItem
' Get the MAPI reference
Set objNameSpace = objOutlook.GetNamespace("MAPI")
' Pick up the Outbox
Set objOutBox = objNameSpace.GetDefaultFolder(olFolderOutbox)
' Add the mail item to the Outbox ...
Set objMail = objOutBox.Items.Add
With objMail
' I usually don't display the new message window, but
' instead do the whole setup in code. Hence, I'm not
' certain that this will actually display the window.
' You'll have to "fiddle" a bit.
.Display
' Stuff I usually do, but if you're displaying the window,
' you'll probably be letting your user do this ...
.Subject = txtSubject.Text
.Body = txtMessage.Text
' Now, let's add an attachment ...
.Attachments.Add attachment_name, olByValue, , attachment_description
End With
[code]
The [i]attachment_name[/i] is the actual file you're going to attach, and [i]attachment_description[/i] is the text that will appear under the attachment.
Note that you can specify the sender and the recipients of the e-mail, but I think that is outside the brief of what you're trying to do, so I've left that code out. You can either play around with the object model and the help the find out how to do it, or post back and I'll give you some sample code for that as well.
Happy mailing,
SmallCraig[upsidedown]