ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Saving to users My Documents (https://www.excelbanter.com/excel-programming/323846-saving-users-my-documents.html)

Rob Edwards

Saving to users My Documents
 
Hi,
When creating code to save a file, how do you specify a users 'My
Documents' folder so that it is determined at run time. Therefore,
dependent on the user, the file will be saved in their C:\Documents and
Settings\'user'\My Documents\, i.e. in my case... C:\Documents and
Settings\REdwards68584\My Documents\

I'm sure it must be easy!

Thanks in advance.

Rob

Rob Edwards

07092 108121

*** Sent via Developersdex
http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

galimi[_2_]

Saving to users My Documents
 
Rob,

You can determine the username path from one of the environment variables.
You can cycle through them with the following code:

Sub allEnviron()
z = 1
doagain:
On Error GoTo Quitapp
Debug.Print Environ(z) & " : # " & z
z = z + 1
GoTo doagain
Quitapp:
End Sub

http://HelpExcel.com

"Rob Edwards" wrote:

Hi,
When creating code to save a file, how do you specify a users 'My
Documents' folder so that it is determined at run time. Therefore,
dependent on the user, the file will be saved in their C:\Documents and
Settings\'user'\My Documents\, i.e. in my case... C:\Documents and
Settings\REdwards68584\My Documents\

I'm sure it must be easy!

Thanks in advance.

Rob

Rob Edwards

07092 108121

*** Sent via Developersdex
http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Rob Bruce

Saving to users My Documents
 
Rob Edwards wrote:
Hi,
When creating code to save a file, how do you specify a users 'My
Documents' folder so that it is determined at run time. Therefore,
dependent on the user, the file will be saved in their C:\Documents
and Settings\'user'\My Documents\, i.e. in my case... C:\Documents and
Settings\REdwards68584\My Documents\

I'm sure it must be easy!

Thanks in advance.

Rob


This works for me - requires a reference to the Windows Scripting Host
Object Model.

Sub SetMyDocs()
Const SPECIAL_FOLDER_MY_DOCS As Long = 16
Dim o As New IWshRuntimeLibrary.WshShell
MsgBox o.SpecialFolders(SPECIAL_FOLDER_MY_DOCS)
End Sub

HTH
--
Rob

http://www.asta51.dsl.pipex.com/webcam/



Tom Ogilvy

Saving to users My Documents
 
Just to Add to Rob's excellent example, to demonstrate late binding
(reference not required)

Sub SetMyDocs()
Const SPECIAL_FOLDER_MY_DOCS As Long = 16
Dim o As Object
Set o = CreateObject("WScript.Shell")
MsgBox o.SpecialFolders(SPECIAL_FOLDER_MY_DOCS)
End Sub

--
Regards,
Tom Ogilvy

"Rob Bruce" <robatanalytical-dynamicsdotcodotyoukay wrote in message
...
Rob Edwards wrote:
Hi,
When creating code to save a file, how do you specify a users 'My
Documents' folder so that it is determined at run time. Therefore,
dependent on the user, the file will be saved in their C:\Documents
and Settings\'user'\My Documents\, i.e. in my case... C:\Documents and
Settings\REdwards68584\My Documents\

I'm sure it must be easy!

Thanks in advance.

Rob


This works for me - requires a reference to the Windows Scripting Host
Object Model.

Sub SetMyDocs()
Const SPECIAL_FOLDER_MY_DOCS As Long = 16
Dim o As New IWshRuntimeLibrary.WshShell
MsgBox o.SpecialFolders(SPECIAL_FOLDER_MY_DOCS)
End Sub

HTH
--
Rob

http://www.asta51.dsl.pipex.com/webcam/





Rob Edwards

Saving to users My Documents
 
Thanks to all!!

Rob Edwards


07092 108121

*** Sent via Developersdex
http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


All times are GMT +1. The time now is 06:04 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com