Vba 只读自定义属性
我设法从VBA中为MS Word添加了自定义属性(元数据),但如何使其成为只读,以便不易更改?您不能 根据您试图避免的场景类型,您可以通过某种方式对内容进行加密来删除属性。这会让用户更难理解如何将它们更改为有用的东西,但不会阻止用户“破坏”它。你不能Vba 只读自定义属性,vba,ms-word,Vba,Ms Word,我设法从VBA中为MS Word添加了自定义属性(元数据),但如何使其成为只读,以便不易更改?您不能 根据您试图避免的场景类型,您可以通过某种方式对内容进行加密来删除属性。这会让用户更难理解如何将它们更改为有用的东西,但不会阻止用户“破坏”它。你不能 根据您试图避免的场景类型,您可以通过某种方式对内容进行加密来删除属性。这将使用户更难找到如何将它们更改为有用的内容,但不会阻止用户“破坏”它。使用文档变量,而不是使用文档属性。您只能通过代码访问它们。他们没有用户界面 以下是我为它们使用的一些旧VB
根据您试图避免的场景类型,您可以通过某种方式对内容进行加密来删除属性。这将使用户更难找到如何将它们更改为有用的内容,但不会阻止用户“破坏”它。使用文档变量,而不是使用文档属性。您只能通过代码访问它们。他们没有用户界面 以下是我为它们使用的一些旧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
使用文档变量,而不是使用文档属性。您只能通过代码访问它们。他们没有用户界面 以下是我为它们使用的一些旧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