SaveAsFile Method

Microsoft Outlook Visual Basic

Show All

SaveAsFile Method

       

Saves the attachment to the specified path.

expression.SaveAsFile(Path)

expression   Required. An expression that returns an Attachment object.

Path   Required String. The location at which to save the attachment.

Example

This Visual Basic for Applications example uses the SaveAsFile method to save the first attachment of the currently open item as a file in the My Documents folder, using the attachment's display name as the file name.

Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.ActiveInspector.CurrentItem
Set myAttachments = myItem.Attachments
myAttachments.Item(1).SaveAsFile "C:\My Documents\" & _
    myAttachments.Item(1).DisplayName

If you use VBScript, you do not create the Application object. This example shows how to perform the same task using VBScript.

Set myItem = Application.ActiveInspector.CurrentItem
Set myAttachments = myItem.Attachments
myAttachments.Item(1).SaveAsFile "C:\My Documents\" & _
    myAttachments.Item(1).DisplayName