2013-11-28 33 views
0

我想在PowerPoint中創建一個變量,這與我打開的演示文稿無關。保存一個變量,保留所有演示文稿中的值

我已經使用ActivePresentation.CustomDocumentProperties之前創建了一個變量,它工作正常,但變量是在演示文稿中創建的,因此當您打開新演示文稿時,您無法獲得此值。我需要類似的東西,但使用Application表達式,所以無論您打開什麼演示文稿,您設置的值都是相同的。

這是可能的Powerpoint?

回答

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