Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I seperate attachments in an email macro

Status
Not open for further replies.

jboyerGAIC

Programmer
Jul 21, 2004
2
US
Is there a way to seperate attachments in an email? I have created a macro that will send 4 reports to a user, but I would like to put each attachment on a seperate line. Any ideas?

Here is basically what I have:

Sub Main()

Dim olapp As Object
Dim oitem As Object
Dim objEmail As Object

Set olapp = CreateObject("Outlook.Application")
Set oitem = olapp.CreateItem(0)
With oitem
.Subject = "Report subject"
.To = "<user@company.com>"
.Body = "Please look at the attached Report(s): "
.Attachments.Add ("\\path\file1.pdf")
.Attachments.Add ("\\path\file2.pdf")
.Attachments.Add ("\\path\file3.pdf")
.Attachments.Add ("\\path\file4.pdf")
.Send
End With

Set olapp = Nothing
Set oitem = Nothing

End Sub

Also, Is there a way to specify who the email is from? This code currently defaults me as the sender.

Thanks!
-Jamie
 
Jamie
If you can use SMTP from your machine to an Exchange server, you can enter a .from line. Attachments also show in the header, rather than the body. (Your network/email administrator would know about SMTP rights, as the ability to relay is often closed on email servers as an anti-spam measure.)

Sub Main()

Dim oitem As Object

Set oitem = CreateObject("CDONTS.NewMail")
With oitem
.Subject = "Report subject"
.To = "user@anyplace.co.uk"
.From = "jamieboy@home"
.Body = "Please look at the attached Report(s): "
.AttachFile ("//path.report1.pdf")
.AttachFile ("//path.report2.pdf")
.Send
End With

Set oitem = Nothing

End Sub


soi la, soi carre
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top