I need to save files in "My Documents" regardless of where it is. How can I
use vba to locate the "My Documents folder" being used and save the file to
it?

Thanks in advance

Re: Locate the My Documents folder with VBA by Jay

Jay
Wed Jun 22 19:36:20 CDT 2005

On Wed, 22 Jun 2005 09:03:02 -0700, neil.mclean@conwy.gov.uk
<neilmcleanconwygovuk@discussions.microsoft.com> wrote:

>I need to save files in "My Documents" regardless of where it is. How can I
>use vba to locate the "My Documents folder" being used and save the file to
>it?
>
>Thanks in advance

Unless somebody comes up with a better method, you can dig it out of
the registry like this:

Dim MyDocsPath As String

MyDocsPath = System.PrivateProfileString( _
FileName:="", _
Section:="HKEY_CURRENT_USER\Software\Microsoft\" _
& "Windows\CurrentVersion\Explorer\Shell Folders", _
Key:="Personal")

MsgBox MyDocsPath

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org

Re: Locate the My Documents folder with VBA by Philippe

Philippe
Wed Jun 22 20:35:41 CDT 2005

"neil.mclean@conwy.gov.uk" <neilmcleanconwygovuk@discussions.microsoft.com>
wrote in message news:9832A8E2-48B8-4161-86FA-28925CADA0B7@microsoft.com...
>I need to save files in "My Documents" regardless of where it is. How can I
> use vba to locate the "My Documents folder" being used and save the file
> to
> it?
>
> Thanks in advance

Make it a VBS script in 5 lines:

Const MY_DOCUMENTS = &H5&
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(MY_DOCUMENTS)
Set objFolderItem = objFolder.Self
Wscript.Echo objFolderItem.Name & ": " & objFolderItem.Path



Re: Locate the My Documents folder with VBA by David

David
Thu Jun 23 08:26:20 CDT 2005

Would this be it?

MyPath = Options.DefaultFilePath(wdDocumentsPath)


Re: Locate the My Documents folder with VBA by Jay

Jay
Thu Jun 23 12:21:05 CDT 2005

David Sisson wrote:
> Would this be it?
>
> MyPath = Options.DefaultFilePath(wdDocumentsPath)

Not necessarily. That retrieves the current setting of the "Documents" item
in the Tools > Options > File Locations dialog. By default that points to
the My Documents folder, but it can be changed by the user to point to any
folder.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org



RE: Locate the My Documents folder with VBA by neilmcleanconwygovuk

neilmcleanconwygovuk
Fri Jun 24 04:20:02 CDT 2005

Thank you all for replying. I will test the solutions provided however this
is the solution that has been adopted and works for my application - in case
someone else needs the answer

' Get MyDocuments folder path
Dim MyDocumentsDirectory
Dim wshShell
Set wshShell = CreateObject("WScript.Shell") MyDocumentsDirectory =
wshShell.SpecialFolders("MyDocuments")

"neil.mclean@conwy.gov.uk" wrote:

> I need to save files in "My Documents" regardless of where it is. How can I
> use vba to locate the "My Documents folder" being used and save the file to
> it?
>
> Thanks in advance