我想问一下,如何才能记住公共变量的价值。我的意思是当我退出outlook时,outlook仍记得这个变量的值,而在下一次,当我再次打开outlook时,它仍然是这个变量的值。
答案 0 :(得分:1)
以下代码用于在Registry(SaveMySettings)中存储信息并检索此信息(RetrieveMySettings)。
该程序保存两个kevaluesys,"项目1"和"项目2"在此注册表项中: HKEY_CURRENT_USER \ Software \ VB和VBA程序设置\我的程序\子程序
Option Explicit
Const Reg_AppName As String = "My Program"
Const Reg_Section As String = "Sub Program"
Sub SaveMySettings()
Dim Reg_Key As String
Dim Reg_Value As String
Reg_Key = "Item 1"
Reg_Value = "First Value"
SaveSetting Reg_AppName, Reg_Section, Reg_Key, Reg_Value
Reg_Key = "Item 2"
Reg_Value = "Second Value"
SaveSetting Reg_AppName, Reg_Section, Reg_Key, Reg_Value
End Sub
Sub RetrieveMySettings()
Dim Value1 As String, Value2 As String
Value1 = GetSetting(Reg_AppName, Reg_Section, "Item 1")
Value2 = GetSetting(Reg_AppName, Reg_Section, "Item 2")
End Sub
答案 1 :(得分:0)
将变量的值保存到文件或注册表中的某个位置。