DocumentBase.SaveAs 方法

使用新名稱或新格式儲存文件。 此方法的部分引數對應到 [另存新檔] 對話方塊中的選項。

命名空間:  Microsoft.Office.Tools.Word
組件:  Microsoft.Office.Tools.Word.v4.0.Utilities (在 Microsoft.Office.Tools.Word.v4.0.Utilities.dll 中)

語法

'宣告
Public Sub SaveAs ( _
    ByRef fileName As Object, _
    ByRef fileFormat As Object, _
    ByRef lockComments As Object, _
    ByRef password As Object, _
    ByRef addToRecentFiles As Object, _
    ByRef writePassword As Object, _
    ByRef readOnlyRecommended As Object, _
    ByRef embedTrueTypeFonts As Object, _
    ByRef saveNativePictureFormat As Object, _
    ByRef saveFormsData As Object, _
    ByRef saveAsAOCELetter As Object, _
    ByRef encoding As Object, _
    ByRef insertLineBreaks As Object, _
    ByRef allowSubstitutions As Object, _
    ByRef lineEnding As Object, _
    ByRef addBiDiMarks As Object _
)
public void SaveAs(
    ref Object fileName,
    ref Object fileFormat,
    ref Object lockComments,
    ref Object password,
    ref Object addToRecentFiles,
    ref Object writePassword,
    ref Object readOnlyRecommended,
    ref Object embedTrueTypeFonts,
    ref Object saveNativePictureFormat,
    ref Object saveFormsData,
    ref Object saveAsAOCELetter,
    ref Object encoding,
    ref Object insertLineBreaks,
    ref Object allowSubstitutions,
    ref Object lineEnding,
    ref Object addBiDiMarks
)

參數

  • fileName
    型別:System.Object%
    文件的名稱。預設為目前的資料夾和檔案名稱。如果未曾儲存過文件,就會使用預設名稱 (例如 Doc1.doc)。如果指定檔名的文件已存在,並不會先提示使用者,而是直接覆寫文件。
  • fileFormat
    型別:System.Object%
    儲存文件的格式。可以是任何的 WdSaveFormat 值。若要使用其他格式儲存文件,請指定適用於 SaveFormat 屬性的值。
  • lockComments
    型別:System.Object%
    true 表示鎖定文件的註解。預設值為 false。
  • password
    型別:System.Object%
    開啟文件的密碼字串。請參閱下方註解。
  • addToRecentFiles
    型別:System.Object%
    true 表示將文件加入至 [檔案] 功能表上最近使用檔案的清單。預設值為 true。
  • writePassword
    型別:System.Object%
    將變更儲存至文件的密碼。請參閱下方註解。
  • readOnlyRecommended
    型別:System.Object%
    true 表示每次開啟文件時,Microsoft Office Word 都會建議採取唯讀狀態。預設值為 false。
  • embedTrueTypeFonts
    型別:System.Object%
    true 表示隨文件一併儲存 TrueType 字型。如果省略,則 EmbedTrueTypeFonts 引數會假設 EmbedTrueTypeFonts 屬性的值。
  • saveNativePictureFormat
    型別:System.Object%
    如果從其他平台 (例如 Macintosh) 匯入圖形,true 表示只儲存 Windows 版本的已匯入圖形。
  • saveFormsData
    型別:System.Object%
    true 表示將使用者輸入至表單的資料儲存為資料錄。
  • saveAsAOCELetter
    型別:System.Object%
    如果文件已附加寄件者,true 表示將文件儲存為 AOCE 信件 (已儲存寄件者)。
  • encoding
    型別:System.Object%
    MsoEncoding.用來將文件儲存為已編碼文字檔的字碼頁或字元集。預設為系統字碼頁。
  • insertLineBreaks
    型別:System.Object%
    如果將文件儲存為文字檔,true 表示在每一行文字末端插入斷行符號。
  • allowSubstitutions
    型別:System.Object%
    如果將文件儲存為文字檔,true 表示允許 Word 使用外觀相似的文字取代某些符號。例如,使用 (c) 代表版權符號。預設值為 false。
  • lineEnding
    型別:System.Object%
    在儲存為文字檔的文件中,Word 標示斷行符號和段落符號的方式。可以是任何的 WdLineEndingType 值。
  • addBiDiMarks
    型別:System.Object%
    true 表示將控制字元加入至輸出檔,在原始文件中保留文字的雙向配置。

備註

避免在您的應用程式中使用固定編碼密碼。 如果程序中需要密碼,請向使用者要求密碼,並將密碼儲存在變數中,再將變數用於程式碼中。

選擇性參數

如需選擇性參數的詳細資訊,請參閱Office 方案中的選擇性參數

範例

下列程式碼範例會使用 SaveAs 方法,採用 RTF 格式和新檔名 myfile.doc 儲存文件。 若要使用這個範例,請在文件層級專案中的 ThisDocument 類別執行。

Private Sub DocumentSaveAs()

    Me.SaveAs(FileName:="myfile.doc", FileFormat:=Word.WdSaveFormat.wdFormatRTF, _
        LockComments:=False, AddToRecentFiles:=True, ReadOnlyRecommended:=False, _
        EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=True, _
        SaveFormsData:=True, SaveAsAOCELetter:=False, _
        Encoding:=Office.MsoEncoding.msoEncodingUSASCII, _
        InsertLineBreaks:=False, AllowSubstitutions:=False, _
        LineEnding:=Word.WdLineEndingType.wdCRLF, _
        AddBiDiMarks:=False)
End Sub
private void DocumentSaveAs()
{
    object FileName = "myfile.doc";
    object FileFormat = Word.WdSaveFormat.wdFormatRTF;
    object LockComments = false;
    object AddToRecentFiles = true;
    object ReadOnlyRecommended = false;
    object EmbedTrueTypeFonts = false;
    object SaveNativePictureFormat = true;
    object SaveFormsData = true;
    object SaveAsAOCELetter = false;
    object Encoding = Office.MsoEncoding.msoEncodingUSASCII;
    object InsertLineBreaks = false;
    object AllowSubstitutions = false;
    object LineEnding = Word.WdLineEndingType.wdCRLF;
    object AddBiDiMarks = false;

    if (this.SaveFormat == (int)Word.WdSaveFormat.wdFormatDocument)
    {
        this.SaveAs(ref FileName, ref FileFormat, ref LockComments,
            ref missing, ref AddToRecentFiles, ref missing,
            ref ReadOnlyRecommended, ref EmbedTrueTypeFonts,
            ref SaveNativePictureFormat, ref SaveFormsData,
            ref SaveAsAOCELetter, ref Encoding, ref InsertLineBreaks,
            ref AllowSubstitutions, ref LineEnding, ref AddBiDiMarks);
    }
}

.NET Framework 安全性

請參閱

參考

DocumentBase 類別

Microsoft.Office.Tools.Word 命名空間