Solved

Excel VBA - Email

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
IT Desktop Support 11 65
Dynamic Excel Input Form 29 28
how to delete specific files and folders with VBA 3 24
Auto Populate Day Month  2 digit Date 4 15
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
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…

815 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

13 Experts available now in Live!

Get 1:1 Help Now