windows VBA 如何获取当前用户应用程序数据文件夹的路径?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/976527/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA How to get path to The Current Users Application data folder?
提问by Binary Worrier
In general,
一般来说,
Using VBA, how do I determine where the Current users Application Data folder is?
使用 VBA,如何确定当前用户应用程序数据文件夹的位置?
The FileSystemObjects special folders only knows about 3 folders
FileSystemObjects 特殊文件夹只知道 3 个文件夹
- WindowsFolder
- SystemFolder
- TemporaryFolder
- 视窗文件夹
- 系统文件夹
- 临时文件夹
Specifically, I need a Word Macro to copy a file to the a folder under the Application Data folder.
具体来说,我需要一个 Word 宏来将文件复制到 Application Data 文件夹下的 a 文件夹中。
e.g. In VB.Net I can use My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData
to do this
例如在 VB.Net 中,我可以用它My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData
来做到这一点
回答by Eric
You can use Environ("AppData")
to get this path. Environ will pull any system variable, which can be found by using the set
command at the DOS prompt.
您可以使用Environ("AppData")
来获取此路径。Environ 将拉取任何系统变量,可以通过set
在 DOS 提示符下使用命令找到这些变量。
回答by Andrew Scagnelli
Using advapi32.dll
, you can get the USERPROFILE
via
使用advapi32.dll
,您可以获得USERPROFILE
通过
Environ("USERPROFILE")
Connect this with the "Application Data" directory (which has a standard, specific name) to get what you want
将此与“应用程序数据”目录(具有标准的特定名称)连接以获得您想要的
CStr(Environ("USERPROFILE") & "\Application Data")
For more information, check out MSDN
有关更多信息,请查看MSDN