SaveAs Method

Microsoft Outlook Visual Basic

Show All

SaveAs Method

       

Saves the Outlook item to the specified path and in the format of the specified file type. If the file type is not specified, the MSG format is used.

expression.SaveAs(Path, Type)

expression   Required. An expression that returns one of the objects in the Applies To list.

Path   Required String. The path in which to save the item.

Type   Optional Variant. The file type to save. Can be one of the following OlSaveAsType constants: olDoc, olHTML, olMSG, olRTF, olTemplate, olTXT, olVCal, or olVCard.

Example

This Visual Basic for Applications example uses the SaveAs method to save the currently open item as a text file in the My Documents folder, using the subject as the file name.

 Dim myItem As Inspector
 Dim objItem As Object
 Set myOlApp = CreateObject("Outlook.Application")
 Set myItem = myOlApp.ActiveInspector
  If Not TypeName(myItem) = "Nothing" Then
      Set objItem = myItem.CurrentItem
      strname = objItem.Subject
      objItem.SaveAs "C:\" & " & strname & .txt", olTXT
  Else
      MsgBox "There is no current active Inspector."
  End If

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

Set myItem = Application.ActiveInspector
  If Not TypeName(myItem) = "Nothing" Then
      Set objItem = myItem.CurrentItem
      strname = objItem.Subject
      objItem.SaveAs "C:\" & " & strname & .txt", 0
  Else
      MsgBox "There is no current active Inspector."
  End If