DocumentBase.Variables 屬性

取得 Variables 集合,表示存放在文件中的變數。

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

語法

'宣告
Public ReadOnly Property Variables As Variables
    Get
public Variables Variables { get; }

屬性值

型別:Microsoft.Office.Interop.Word.Variables
Variables 集合,表示存放在文件中的變數。

範例

下列程式碼範例會將文件變數加入至文件中,然後顯示訊息說明文件變數的值。 若要使用這個範例,請在文件層級專案中的 ThisDocument 類別執行。

Private Sub DocumentVariables()
    Dim value As Object = "197"
    Dim variableName As Object = "BirthYear"
    Me.Variables.Add(CStr(variableName), value)
    MessageBox.Show(Me.Variables.Item(variableName).Value.ToString() & "0")
End Sub 
private void DocumentVariables()
{
    object value = "197";
    object variableName = "BirthYear";
    this.Variables.Add((string)variableName, ref value);
    MessageBox.Show(this.Variables.get_Item(
        ref variableName).Value + 0);
}

.NET Framework 安全性

請參閱

參考

DocumentBase 類別

Microsoft.Office.Tools.Word 命名空間