Store settings on user PC

前端 未结 1 544
傲寒
傲寒 2021-01-01 02:07

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 in

相关标签:
1条回答
  • 2021-01-01 02:43

    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 ("").

    0 讨论(0)
提交回复
热议问题