Save settings to user's PC

I have an Excel worksheet with a script and it is saved in a remote place that every user can access. This macro will allow the user to select the destination folder and create some files inside.

Now I want my script to remember the last selected path for each user. I may need to save more paths (variables) in the future.

My idea is to store this data in a place Environ("AppData")on each user's computer. The type of offline cookie.

But what will be the easiest way to create (if it does not exist) read and update a file with several that I want to access?

I tried to save it in notepad, but indexing and parsing were a nightmare.

+4
source share
1 answer

Save the settings in the registry.

SaveSetting (application name, section, key, setting)

SaveSetting "AffectedTerminals", "frmMain", "LastDir", szPathname

You can then get the settings using getetting the next time you launch the application so that you can use it.

GetSetting (application name, section, key [, default])

Dim szLastDir As String
szLastDir = GetSetting("AffectedTerminals", "frmMain", "LastDir", "P:\AttEngineering")

EDIT: arguments to appname and section.
The application name and section can be whatever you want. Something that describes the setup is best. In the above code, AffectedTerminals was the name of my application. Therefore, if you have a spreadsheet that processes invoices, you can name the application name "ITinvoices". A section is only a subsection (view of a subdirectory) for register entries.

HKEY_CURRENT_USER/ / VB VBA/ ////

enter image description here

SaveSetting

AppName
. , , .


. , , .

Key
. , .


. , , .

GetSetting

_
. , , .


. , , .


. , .


. , , . , , ("").

+10

Source: https://habr.com/ru/post/1610428/


All Articles