Visual Basic for Applications (VBA) is commonly used to automate routine tasks in Microsoft Office applications. Sending an e-mail from Microsoft Excel 2007 using VBA is useful in cases when you need to continuously e-mail the latest data in an Excel workbook. In a few steps you can write code to easily automate the task of sending the email through Microsoft Outlook.
- Skill level:
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."
Type the following to create a new sub:
Type the following to create your variables:
Dim oLookApp As Outlook.Application
Dim oLookMail As Outlook.MailItem
Type the following to assign the outlook object and create a new e-mail:
Set oLookApp = New Outlook.Application
Set oLookMail = oLookApp.CreateItem(0)
Type the following to define the variables for your e-mail:
.To = "email@example.com"
.Subject = "My Workbook"
.Body = "I'm e-mailing this workbook.."
Execute your sub to e-mail the current Excel workbook.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for