WriteToFile Method (Attachment Object)

The WriteToFile method saves the attachment to a file in the file system.

Syntax

objAttachment.WriteToFile(fileName)

objAttachment
Required. The Attachment object.
fileName
Required. String. The full path and file name for the saved attachment, for example C:\DOCUMENT\BUDGET.XLS.

Remarks

The WriteToFile method overwrites the file without warning if a file of that name already exists. Your application should check for the existence of the file before calling WriteToFile.

The WriteToFile method operates differently, depending on the value of the Attachment object's Type property. The following table describes its operation:

Attachment Type property WriteToFile operation
CdoFileData Copies the contents of the attachment to the specified file.
CdoFileLink (Not supported)
CdoOLE Writes the attachment to the specified file in OLE docfile format. The file can subsequently be read by the ReadFromFile method with an CdoOLE type setting.
CdoEmbeddedMessage (Not supported)

The term "OLE docfile" indicates that the file is written by an application such as Microsoft® Word 6.0 or later that writes files using the OLE IStorage and IStream interfaces.

Note The current version of CDO does not support WriteToFile for CdoFileLink or CdoEmbeddedMessage attachments. These calls generate the run-time error CdoE_NO_SUPPORT.