working outlook application
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

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

Working with the Outlook application

resolvedResolved · Medium Priority · Version 2003

replyReply Wed 11 Nov 2009, 16:03Delegate William said...

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

For upcoming training course dates see: Pricing & availability

replyReply Thu 12 Nov 2009, 13:22Trainer Stephen said...

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

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

 

Please browse our web site to find out more about
microsoft excel training courses and other Microsoft training courses.

Excel tip:

Display Functions on Worksheets

Functions in Excel can be difficult to recall their format/syntax

For example, you want to use the =PMT function.

Enter =PMT, then select keystroke, CTRL+SHIFT+A.

This usful memory jog, will display the arguments of a function on a worksheet, allowing the user to proceed with the generation of the function



View all Excel hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard