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

resolvedResolved · Medium Priority · Version 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:

Cycling through Absoulte cell references

If you are working with formulas in excel and need to convert your formula to an absolute formula, instead on manually adding in the $dollar signs you can highlight the specific part of your formula and press the F4 key.

You can cycle through all the absolute options by pressing the button (up to four times)

View all Excel hints and tips


Server loaded in 0.08 secs.