gpt4 book ai didi

Word 变量集合的 Excel VBA 等效项

转载 作者:行者123 更新时间:2023-12-04 21:42:18 25 4
gpt4 key购买 nike

Excel VBA (Office 16) 是否具有与 Word VBA 等效或相似的属性 ActiveDocument.Variables收藏?我想在文档中保存项目值,而不必使用隐藏表。

最佳答案

您可以使用 Name 对象永久保留所需的值。 Name 对象通常指的是一个单元格或一组单元格,甚至是整个工作表。但它也可以用于存储公式并以这种方式保存数据。
如果您使用此功能,建议您命名您的变量名称,以便它们与其他 Name 对象的其余部分一样清晰可辨。此外,您可以隐藏它们以避免误用。请参见下面的示例代码:

Sub fnCreateNamesAsVariablesAndHideThem()
'the False parameter hides the name to the front-end

With ThisWorkbook.Names
.Add "var_intNumber", 7, False
.Add "var_strTitle", "Gone with the Wind", False
.Add "var_LngPtr", 1127654, False
End With

Debug.Print Names("var_strTitle")
Debug.Print Names("var_LngPtr")
'you can use them in a cell, like: =var_LngPtr, even hidden.
End Sub
重要的是要注意,在创建名称时,不会评估另一个名称的可能存在:它将始终被覆盖。
在网络上提到了其他实现此目的的方法,例如写入 Windows 注册表、创建“自定义属性”等。它们的制作和阅读更加费力。

关于Word 变量集合的 Excel VBA 等效项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72703770/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com