?
Solved

Automated e-mail from VB application

Posted on 2002-06-18
7
Medium Priority
?
134 Views
Last Modified: 2010-05-02
I'm using the following code line to open Outlook with a new message containing a To: address and subject line.

ShellExecute Me.hwnd, "Open", "MailTo:myname@mailserver.com?Subject=A certain subject line", "", "", 0&


It works fine, but I'd like to be able to specify an attachment also, so the user has as little to do as possible. Is there a way to do this?

Thanks.
0
Comment
Question by:rdolivaw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 4

Expert Comment

by:gencross
ID: 7090013
Here is some code that will open Outlook and mail with attachments

Sub Email()
   
    Dim objOL As Object
    Dim objEMail As Object
   
    Set objOL = CreateObject("Outlook.Application") 'opens Outlook
   
    Set objEMail = objOL.CreateItem(olMailItem) ' opens new email
    With objEMail
        .Recipients.Add "me@me.com" 'recipient's email address
        .Subject = "Your details " & x 'subject of the email
        .Body = "Details"
        'To send an attachment
        .Attachments.Add ("C:\my documents\file.txt")
        .Send
    End With
   
    Set objEMail = Nothing
       
End Sub

This should do it if I did not forget anything.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 7090210
have a look at this free an easy mail object: http://www.freevbcode.com/ShowCode.Asp?ID=109
0
 
LVL 11

Accepted Solution

by:
arana earned 200 total points
ID: 7090213
outlook supports file attachments via shellexecute, but other mailers probably dont support it:

pCh = "mailto:myname@mailserver.com?subject=your_subject&body=your_body&file=" & chr(34) & "c:\autoexec.bat" & chr(34)


ShellExecute Me.hwnd, "Open", pCh, "", "",
0&
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7090378
Listening...
0
 

Author Comment

by:rdolivaw
ID: 7090650
arana:

Thanks for the help. The other two were extremely helpful, too, but since all my users have Outlook as their default e-mail program, your solution was easier than those.

Thanks to you other responders, too. Most helpful and interesting information.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7090714
Arana, i did try your code but i didn't get any attachment.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7090720
Sorry, i did try with Outlook Express ;)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month13 days, 14 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question