You can store information relating to your Excel application in the registry. VBA provides an easy way to set and retrieve that information via the SaveSetting and GetSetting statements.
The arguments for these statements are AppName, Section, Key, and Setting. All of these arguments are data that you create. That is, there’s no right or wrong AppName, it’s whatever you want it to be. To be fair, there are some situations where that data can be wrong. First, when you using GetSetting, you have to specify the correct arguments ñ the same ones you used when with SaveSetting. If you don’t, you won’t get the correct information. Also, if you use the same arguments as some other program that’s storing information in the registry, you will overwrite it/get the wrong data and generally create havoc. To avoid that, make sure you are using unique AppNames.
With SaveSetting, VBA creates the registry entry if it doesn’t exist. If the entry doesn’t exist when you use GetSetting, you get an empty string.
Below are three subs that demonstrate the use of GetSetting and SaveSetting. The sub ChangeName saves a name to the registry and the function GetName retrieves it.
Sub ChangeName(sName As String)
SaveSetting appname:=”Euchre”, _
GetName = GetSetting(appname:=”Euchre”, _
Once ChangeName is run, the registry looks like this: