20

In general,

Using VBA, how do I determine where the Current users Application Data folder is?

The FileSystemObjects special folders only knows about 3 folders

  • WindowsFolder
  • SystemFolder
  • TemporaryFolder

Specifically, I need a Word Macro to copy a file to the a folder under the Application Data folder.

e.g. In VB.Net I can use My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData to do this

2 Answers 2

39

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.

2
  • I never thought to check the Environment strings, this works a treat, thanks :) Jun 10, 2009 at 16:18
  • 2
    I think the Environ() approach is unreliable as environmental variables can be changed by the user and can lead to unexpected results. Using the Windows API might be better. Here's an example for finding the Documents / My Documents folder: dailydoseofexcel.com/archives/2009/02/26/… If you can find a way to do it for the AppData folder it could be a better way. Feb 18, 2014 at 22:23
16

Using advapi32.dll, you can get the USERPROFILE via

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

1
  • 2
    Alternative to converting to a string with CStr() is to just explicitly ask for the string data type using its type character $ before runtime - Environ$(). Mar 19, 2019 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.