ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Output file to My Documents (https://www.excelbanter.com/excel-programming/417494-output-file-my-documents.html)

scdallas

Output file to My Documents
 
I'm trying to write a macro in a file located on a shared drive that will be
used by various members of my team. It needs to Open a file for Output and
I'd like it to save the file to the My Documents folder of whoever is running
the macro. Is there a way to do this either using the UserName in the file
name or can "My Documents" be identified without putting a full path (ie
c:\Documents and Settings\username\My Documents\...)? I'm using Excel 2003.

Gary Keramidas

Output file to My Documents
 

this has always worked for me. some say it doesn't, but i've never had any
issues.

environ("UserProfile") & "\My Documents\"

--


Gary


"scdallas" wrote in message
...
I'm trying to write a macro in a file located on a shared drive that will be
used by various members of my team. It needs to Open a file for Output and
I'd like it to save the file to the My Documents folder of whoever is running
the macro. Is there a way to do this either using the UserName in the file
name or can "My Documents" be identified without putting a full path (ie
c:\Documents and Settings\username\My Documents\...)? I'm using Excel 2003.




JP[_4_]

Output file to My Documents
 
Modified from an old Dave Peterson post:

Dim strMyDoc As String

strMyDoc = MyDocPath

Function MyDocPath() As String
' returns path to "My Documents" as a String
Dim WSHShell As Object

Set WSHShell = CreateObject("WScript.Shell")
MyDocPath = WSHShell.SpecialFolders("MyDocuments")

Set WSHShell = Nothing
End Function

ActiveWorkbook.SaveAs strMyDoc & "\" & "myfile.xls"


--JP

On Sep 23, 12:13*pm, scdallas
wrote:
I'm trying to write a macro in a file located on a shared drive that will be
used by various members of my team. *It needs to Open a file for Output and
I'd like it to save the file to the My Documents folder of whoever is running
the macro. *Is there a way to do this either using the UserName in the file
name or can "My Documents" be identified without putting a full path (ie
c:\Documents and Settings\username\My Documents\...)? *I'm using Excel 2003.



scdallas

Output file to My Documents
 
Thanks so much! It worked for me! I simply substituted
environ("UserProfile") in the portion of my Open statement where I had
hard-coded the location of MY My Documents folder and sure enough, my output
file was where I expected it to be!

Sue

"Gary Keramidas" wrote:

this has always worked for me. some say it doesn't, but i've never had any
issues.

environ("UserProfile") & "\My Documents\"

--


Gary


"scdallas" wrote in message
...
I'm trying to write a macro in a file located on a shared drive that will be
used by various members of my team. It needs to Open a file for Output and
I'd like it to save the file to the My Documents folder of whoever is running
the macro. Is there a way to do this either using the UserName in the file
name or can "My Documents" be identified without putting a full path (ie
c:\Documents and Settings\username\My Documents\...)? I'm using Excel 2003.






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

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