Prev: Need to close Word when it won't quit.
Next: Delete rows in table if checkbox value in first cell equals true
From: wal on 16 Dec 2009 12:03 Word 2007 Vista Enterprise I have a macro that tests for a certain path; the path is something like: C:\Users\JohnSmith\Documents Other people in my organization might find this macro useful. Is there a generic way to designate the person's User folder (i.e., the "JohnSmith" folder in my example) in VBA, so I don't have to rewrite the path code for each person? Thanks.
From: Klaus Linke on 16 Dec 2009 12:34 "wal" <ress6oy8(a)verizon.net> wrote: > Word 2007 > Vista Enterprise > > I have a macro that tests for a certain path; the path is something > like: > > C:\Users\JohnSmith\Documents > > Other people in my organization might find this macro useful. Is > there a generic way to designate the person's User folder (i.e., the > "JohnSmith" folder in my example) in VBA, so I don't have to rewrite > the path code for each person? You should be able to retrieve it from the Registry... Not sure, I guess it would be System.PrivateProfileString("", "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", "Personal") You can also get Word's default file path with Options.DefaultFilePath(Path:=wdDocumentsPath) .... but that may be set to whatever path the user last used, and likely is not what you want. Regards, Klaus
From: Jonathan West on 16 Dec 2009 13:21
"wal" <ress6oy8(a)verizon.net> wrote in message news:7148f4a7-9164-4818-83bf-ebfd91dc0f4b(a)g12g2000vbl.googlegroups.com... > Word 2007 > Vista Enterprise > > I have a macro that tests for a certain path; the path is something > like: > > C:\Users\JohnSmith\Documents > > Other people in my organization might find this macro useful. Is > there a generic way to designate the person's User folder (i.e., the > "JohnSmith" folder in my example) in VBA, so I don't have to rewrite > the path code for each person? > Karl Peterson has written a class module you can drop into your project, which will retrieve for you a whole range of special folders. http://vb.mvps.org/samples/SysFolders/ Much better to use the Windows API calls for this (as Karl does) than to attempt to guess the folder paths or even retrieve them directly from the registry. Folder locations and even registry keys come & go, but even Microsoft would not dare to mess with the API calls - to do so would cause just about every significant Windows program in existence to stop working. So using Karl's class module means that as folder locations change between versions of windows, your code will still work. For instance, under Windows XP, the equivalent folder is C:\Documents and Settings \JohnSmith\My Documents. The code will provide the appropriate folder depending on the user name and the version of Windows. -- Regards Jonathan West |