全部显示

SaveAs 方法

       

将 Outlook 项目以指定文件类型的格式保存到指定的路径。如果没有指定文件类型,则使用 MSG 格式。

expression.SaveAs(Path, Type)

expression  必选。该表达式返回“应用于”列表中的一个对象。

Path  必选,String 类型。将项目保存到的路径。

Type  可选,Variant 类型。要保存的文件类型。可以为以下 OlSaveAsType 常量之一:olDocolHTMLolMSGolRTFolTemplateolTXTolVCalolVCard

示例

本 Visual Basic for Applications 示例使用 SaveAs 方法将当前打开的项目作为文本文件保存在“My Documents”文件夹中,使用主题作为文件名。

 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

如果使用 VBScript,您不必创建 Application 对象,而且也不能使用命名常量。本示例说明如何使用 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