Solved

Excel VBA - Email

Posted on 2012-03-09
4
301 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

914 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

15 Experts available now in Live!

Get 1:1 Help Now