如何使用VBA将变量永久存储在Word 2010文档中?

Sin*_*ard 2 variables vba ms-word word-vba word-2010

我知道如何在使用VBA的Word 2010中使用变量。但是,当文档关闭并重新打开时,它们全部重置。

如何将变量永久存储在Word文档中?

ZAT*_*ZAT 5

可以使用:

Sub Test()
ActiveDocument.Variables.Add Name:="PermanentVar", Value:=100
'ActiveDocument.Variables("PermanentVar").Delete
End Sub
Run Code Online (Sandbox Code Playgroud)

检查是否保留:

Private Sub Document_Open()
Msgbox ActiveDocument.Variables("PermanentVar")
End Sub
Run Code Online (Sandbox Code Playgroud)

参考MS kb链接

参考链接