I would like to ask How can outlook remember value of public variable. I mean when I exit outlook, outlook still remember value of this variable and In the next time, when I open outlook again, It still remain value of this variable.
Asked
Active
Viewed 78 times
0
-
What does this question have to do with Excel? – Ron Rosenfeld Oct 22 '16 at 14:20
-
@Bruce, it seems a follow up of [this question](http://stackoverflow.com/questions/40191712/set-default-public-variable-at-the-first-time-and-increase-it-in-the-next-time#40192228): proper feedback from you would help both you and people trying at helping you. thanks – user3598756 Oct 24 '16 at 09:09
2 Answers
1
The following has code to store information in the Registry (SaveMySettings) and retrieve this information (RetrieveMySettings).
The program saves two kevaluesys, "Item 1" and "Item 2" in this Registry key: HKEY_CURRENT_USER\Software\VB and VBA Program Settings\My Program\Sub Program
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

Jon Peltier
- 5,895
- 1
- 27
- 27
0
Either persist the value of the variable to a file or to a place in the registry.

S Meaden
- 8,050
- 3
- 34
- 65
-
Could you please tell me more detail or give some reference document about that. It seem to be you mention SaveSetting and GetSetting Function which I have just searched – Bruce Oct 22 '16 at 14:25
-
There are examples here http://stackoverflow.com/questions/11503174/how-to-create-and-write-to-a-txt-file-using-vba and here http://stackoverflow.com/questions/11528694/read-parse-text-file-line-by-line-in-vba – niton Oct 22 '16 at 16:20