Solved

Excel VBA - Email

Posted on 2012-03-09
4
290 Views
Last Modified: 2012-08-13
How Can I write a VBA and email the current file to different people and hard some of the message, and some variables (including the topic) with message box
0
Comment
Question by:desmondwkng
  • 2
4 Comments
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 500 total points
ID: 37705519
Try for example:

Sub sendamail()
Dim str As String

    str = InputBox("Identify any extra recipients", "Recipient Entry")
    With Application.CreateItem(olMailItem)
        .Subject = "My Subject"
        .Body = "Mail Body" & vbCrLf & vbCrLf & "And it all starts here"
        .To = "fred@fred.com, doris@doris.com"
        If str <> "" Then .To = .To & "," & str
        .Display
    End With
    
End Sub

Open in new window


Chris
0
 
LVL 4

Expert Comment

by:SmittyPro
ID: 37705558
See: www.rondebruin.nl/sendmail.html

He's got all the Outlook code examples you'll ever need.

HTH,
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 37705643
The same thing from a different application is as follows:

Sub sendamail()
Dim str As String
Dim olkApp As Object

    str = InputBox("Identify any extra recipients", "Recipient Entry")
    Set olkApp = CreateObject("outlook.application")
    With olkApp.CreateItem(0)
        .Subject = "My Subject"
        .Body = "Mail Body" & vbCrLf & vbCrLf & "And it all starts here"
        .To = "fred@fred.com, doris@doris.com"
        If str <> "" Then .To = .To & "," & str
        .Display
    End With
    
End Sub

Open in new window


Chris

Note replacing .display with .send will simply send the email ... if that is required in the application.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
Outlook Free & Paid Tools
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now