Having to deploy a VBA application on several computers under Windows XP, I needed to automatically create a particular file in an universal place, independent of hard drives, directory structure, even the OS language: the root directory of the C drive, namely C:\
This worked fine ... until these computers started to migrate to Vista or Windows 7, which I discovered don't easily allow writing on the C drive. What could be an alternate universal writable location that would work under any version of Windows, in any language, for all users?
Call a Windows API that returns the path to a SpecialFolder
on the respective machine and use that - well suited are for example
CSIDL_COMMON_DOCUMENTS
(non-user-specific)CSIDL_COMMON_APPDATA
(non-user-specific)CSIDL_APPDATA
(user-/app-specific)CSIDL_MY_DOCUMENTS
(user-specific)The Windows API takes care of all that you described - locations above are writeable, work for all Windows versions and not language-dependent.
For VBA source code and samples see http://www.cpearson.com/excel/SpecialFolders.aspx
For MSDN references see: