只读自定义属性
答
而不是使用文档属性使用文档变量(http://msdn.microsoft.com/en-us/library/bb212231.aspx)。您只能通过代码访问它们。他们没有UI。
这里的一些老VB6/VBA功能我用他们:
Public Sub SetVariable(oDocument As Word.Document, sName As String, sValue As String)
Dim oVariable As Word.Variable
Set oVariable = LocateVariable(oDocument, sName)
If Not oVariable Is Nothing Then
oVariable.Value = sValue
Else
oDocument.Variables.Add sName, sValue
End If
End Sub
Public Function GetVariable(oDocument As Word.Document, sName As String) As String
Dim oVariable As Word.Variable
Set oVariable = LocateVariable(oDocument, sName)
If Not oVariable Is Nothing Then
GetVariable = oVariable.Value
Else
GetVariable = ""
End If
End Function
Public Function LocateVariable(oDocument As Word.Document, sName As String) As Word.Variable
Dim oVariable As Word.Variable
For Each oVariable In oDocument.Variables
If StrComp(oVariable.Name, sName, vbTextCompare) = 0 Then
Set LocateVariable = oVariable
Exit Function
End If
Next
Set LocateVariable = Nothing
End Function