SaveAsFile Method Example

SaveAsFile Method 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