1

I have a variable that stores a file path. If the file is missing, the application prompts the user to select a new file. How can I save the new file path for the next time the user opens the program?

I know I could write the file path to a table and then retrieve it at runtime, but is there a way to do it strictly in VBA code?

1
  • 2
    SaveSetting / GetSetting is the simplest (Uses the registry) Commented Aug 11, 2015 at 15:28

1 Answer 1

1

As Alex K. said. This will save and retrieve values from the registry. For NameOfYourProject you might want to use the spreadsheet name or something.

SaveSetting "NameOfYourProject", "frmMain", "LastPath", szLastPath

szLastPath = GetSetting("NameOfYourProject", "frmMain", "LastPath", 0)

Here are the parameters for SaveSettings.

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.

And these for GetSetting

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.