保存一个仍然是所有演示文稿中的值的变量

时间:2013-11-28 11:10:43

标签: vba powerpoint-vba

我想在powerpoint中创建一个变量,这与我打开的演示文稿无关。

我之前使用ActivePresentation.CustomDocumentProperties创建了一个变量,它工作正常,但变量是在演示文稿中创建的,所以当你打开一个新的演示文稿时,你无法获得这个值。我需要类似的东西,但使用Application表达式,因此无论您打开什么演示文稿,您设置的值都是相同的。

这在powerpoint中可能吗?

1 个答案:

答案 0 :(得分:0)

为此,您需要将值保存到注册表中。虽然您可以调用Win API来执行此操作,但它有点复杂,如果您在Mac上运行代码将无法工作。

而是使用内置的VBA SaveSetting和GetSetting命令。

Sub Thing()

' Save some values to the registry:

SaveSetting "MyApp", "Settings", "MySetting1", "MyValue1"
SaveSetting "MyApp", "Settings", "MySetting2", "MyValue2"
SaveSetting "MyApp", "Settings", "MySetting3", "MyValue3"
' Saves Setting/Value pairs to
' HKEY_CURRENT_USER\Software\VB and VBA Program Settings\MyApp\Settings

' Get one of the saved values:
Debug.Print GetSetting("MyApp", "Settings", "MySetting1")

' Get one of the saved values and return a default value if there's no such saved value:
Debug.Print GetSetting("MyApp", "Settings", "MySetting42", "The Answer To Life, Universe, et al")

' List
Dim lCount As Long
Dim MySettings As Variant

MySettings = GetAllSettings("MyApp", "Settings")

For lCount = LBound(MySettings, 1) To UBound(MySettings, 1)
    Debug.Print MySettings(lCount, 0), MySettings(lCount, 1)
Next

' Remove all of the settings:
DeleteSetting "MyApp", "Settings"


End Sub