Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


April 22, 2002

Working with Attachments


RSS
Subscribe to Windows IT Pro | See More Scripting Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Add, save, and open Outlook-item attachments

Many common Outlook operations center on attachments—adding them to messages and other items, opening them, and saving them as system files. Let’s explore how Outlook programmers work with attachments and look at the Scripting Runtime programming library, which comes in handy when working with file attachments.

Adding an Attachment
Every Outlook item, except the yellow-sticky-note NoteItem object, supports an Attachments collection. Like other collections, the Attachments collection supports an Add method to attach a new file, an Item method to help enumerate the attachments in the collection, and a Remove method to delete an attachment from the item. However, the Remove method doesn’t work in all versions of Outlook, so I recommend avoiding it.

When you attach a file to an Outlook item, you must provide either the path to a file on your system or an Outlook item object, such as a ContactItem or MailItem. Other parameters are optional. Unfortunately, the Help file for Outlook 2002 displays the details of the AddressEntries.Add method instead of the Attachments.Add method. You can find information about Attachments.Add at http://support.microsoft.com/support/office/inprodhlp/outlook/olmthaddattachmentsobj.asp, but this Web page doesn’t tell the whole story.

The basic syntax for adding a file as an attachment to a new Outlook message looks like this:

Set objOL = _
    CreateObject("Outlook.Application")
Set objMsg = _
    objOL.CreateItem(olMailItem)
Set objAttachments = _
    objMsg.Attachments
Set objAtt = _
    objAttachments.Add("c:\myfile.doc")
   Previous  [1]  2  3  Next 


Top Viewed ArticlesView all articles
WinInfo Short Takes: Week of November 23, 2009

An often irreverent look at some of the week's other news, including some post-PDC some soul searching, a Google Chrome OS announcement and a Microsoft response, Windows 7 off to a supposedly strong start, the Jonas Brothers and Xbox 360, and so much more ...

Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

2009 Windows IT Pro Editors' Best and Community Choice Awards

Picking a favorite product from an impressive crowd of competitive offerings is never an easy task, and such was the case with our Editors' Best and Community Choice awards this year. ...


Scripting Whitepapers From Development to Production: Streamlining SharePoint Deployment with DocAve Deployment Manager

Take Control of Your Email: Understand the Business Reasons for Email Storage Management

Related Events Deep Dive into Windows Server 2008 R2 presented by John Savill

Bail Out Your Exchange Environment

Continuous Application Virtualization: An Answer to Exchange Recovery Problems

Check out our list of Free Email Newsletters!

Scripting eBooks Keeping Your Business Safe from Attack: Encryption and Certificate Services

Best Practices for Managing Linux and UNIX Servers

Building an Effective Reporting System

Related Scripting Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement