I have an Excel sheet with a script and it's saved on a remote location that every user can access. This macro will let user select a target folder and create some files inside.
Now I want my script to remember the last chosen path of each user. I might need to store more paths (variables) in the future.
My idea is to store those data in a Environ("AppData")
location on each users' computer. Sort of an offline cookie.
But what would be the easiest way to create (if it doesn't exist) read from and update file with multiple that I want to easily access?
I've tried it saving in notepad, but indexing and parsing was nightmare.
Save the settings to the registry.
SaveSetting (appname, section ,key ,setting)
SaveSetting "AffectedTerminals", "frmMain", "LastDir", szPathname
Then you can retrieve the setting with getsetting the next time your app runs so you can use it.
GetSetting ( appname , section, key [, default ] )
Dim szLastDir As String
szLastDir = GetSetting("AffectedTerminals", "frmMain", "LastDir", "P:\AttEngineering")
EDIT: appname and section arguments explained.
The appname and section can be anything you want. Something that describes the setting is best. In the above code AffectedTerminals was the name of my application. So if you have a spreadsheet that handles IT invoices then you might call the appname "ITinvoices". The section is just a sub section (sort of a sub-directory) for the regestry entry.
The setting will be saved at this locatioin
HKEY_CURRENT_USER/Software/VB and VBA Program Settings/appname/Section/key/value/
So for mine it is saved as
SaveSetting Function
AppName
Required. String expression containing the name of the application or project to which the setting applies.
Section
Required. String expression containing the name of the section in which the key setting is being saved.
Key
Required. String expression containing the name of the key setting being saved.
Setting
Required. Expression containing the value to which Key is being set.
GetSetting Function
appname
Required. string expression containing the name of the application or project whose key setting is requested.
section
Required. String expression containing the name of the section where the key setting is found.
key
Required. String expression containing the name of the key setting to return.
default
Optional. Expression containing the value to return if no value is set in the key setting. If omitted, default is assumed to be a zero-length string ("").
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With