本文介绍了在用户PC上存储设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有脚本的Excel工作表,它保存在每个用户可以访问的远程位置。
此宏将允许用户选择一个目标文件夹并在其中创建一些文件。



现在我想让我的脚本记住每个用户的最后选择的路径。我可能需要在将来存储更多路径(变量)。



我的想法是将这些数据存储在一个 Environ(AppData)中每个用户的计算机上的位置。排序一个离线的cookie。



但是,最简单的创建方式(如果不存在)会从多个我想要轻松地读取和更新文件访问?



我已经尝试保存在记事本中,但索引和解析是噩梦。

解决方案

将设置保存到注册表。



  SaveSettingAffectedTerminals,frmMain,LastDir,szPathname 

然后,您可以在下次运行应用程序时检索设置,以便您可以使用它。



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

编辑:appname解释部分参数。

该appname和section可以是任何你想要的。描述设置的东西最好。在上面的代码中,AffectedTerminals是我的应用程序的名称。因此,如果您有一个处理IT发票的电子表格,那么您可以将该名称称为ITInvoices。该部分只是注册表条目的子部分(子目录)。



该设置将保存在此位置

所以对于我的它保存为



SaveSetting功能



AppName

必填。包含应用程序或项目名称的字符串表达式。



部分

必需。包含保存键设置的部分的名称的字符串表达式。



密钥

必需。包含要保存的密钥设置的名称的字符串表达式。



设置

必需。包含正在设置键的值的表达式。



GetSetting功能



appname

必填。包含请求其密钥设置的应用程序或项目的名称的字符串表达式。



部分

必需。包含找到密钥设置的部分的名称的字符串表达式。





必需。包含要返回的键设置的名称的字符串表达式。



默认

可选。包含返回值的表达式,如果在键设置中未设置任何值。如果省略,则默认值为零长度字符串()。


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 "AffectedTerminals", "frmMain", "LastDir", szPathname

Then you can retrieve the setting with getsetting the next time your app runs so you can use it.

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

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

这篇关于在用户PC上存储设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 13:15