Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

working outlook application

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Working with the Outlook application

Working with the Outlook application

ResolvedVersion 2003

William has attended:
Excel VBA Intro Intermediate course
Excel Advanced course

Working with the Outlook application

I was wondering if you had any code to hand that would allow me to open and compose a new email, attach an excel spreadsheet and then send it to a designated recipient using Excel VBA?

Beyond this, could you point me in the direction of the Microsoft add-in that turns off the automatic warnings when composing and sending emails via code?

Many thanks,

Wil House

RE: Working with the Outlook application

Hi William

Thank you for your question

The required code is given below. There are two procedures, and the second one calls the first one

[code]Public Sub SendEmail(ByVal Recipient As String, ByVal Attachment As String)
Dim Outlook As Object
Dim NameSpace As Object
Dim MailItem As Object

Set Outlook = CreateObject("Outlook.Application")
Set MailItem = Outlook.CreateItem(0)
With MailItem
.Subject = "Employee Report"
.Recipients.Add Recipient
.Body = "Workbook attached"
.Attachments.Add Attachment
.Send
End With
End Sub

Sub MailCall()
strAddress = InputBox("Enter Email Address")
strFileName = "C:\VBA + Complete.xls" 'needs to change to reflect actual location

Application.DisplayAlerts = False
SendEmail strAddress, strFileName
Application.DisplayAlerts = True

End Sub/code]

Hope this is useful

Regards

Stephen

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Excel 2010 Shortcuts - Start and End of the Worksheet

Did you know you can quickly move to either the beginning or the end of an Excel Worksheet using just a couple of keys on the keyboard?

Press Ctrl + Home key to move the cursor to cell A1

Press Ctrl + End key to move the cursor to the end of the current worksheet.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.