Saturday, July 14, 2012

How to Send Email Using Excel 2007 VBA


1. Start Microsoft Office 2007 and select the 'Developer' tab. Click on 'Visual Basic' and select 'Tools.' Click on 'References' check 'Microsoft Outlook 12.0 Object Library' and select 'OK.'
2. Type the following to create a new sub:Sub sendEmail()Press 'Enter.'
3. Type the following to create your variables:Dim oLookApp As Outlook.ApplicationDim oLookMail As Outlook.MailItem
4. Type the following to assign the outlook object and create a new email:Set oLookApp = New Outlook.ApplicationSet oLookMail = oLookApp.CreateItem(0)
5. Type the following to define the variables for your email:With oLookMail.To = 'john.doe@yahoo.com'.Subject = 'My Workbook'.Body = 'I'm e-mailing this workbook..'.Attachments.Add ActiveWorkbook.FullName.sendEnd With
6. Execute your sub to email the current Excel workbook.

Blogger news