PDA

View Full Version : Environmental variables to get to ?My Docs? or "My Documents" location.



RyanT
07-13-2008, 10:24 PM
Don?t want to hard code my output path since not everyone uses the default My Docs location. i would like to save a file in My Docs\time sheets\xxx.xls regardless of where the user?s my docs might be. Is there a simple way to do this. Something like: %docs%\time sheets\


Right now I have a text box (txtPath) where the user can enter the path they want but the problem is if the user sync?s the xls files between 2 computers with different My Docs locations

Dim FileName As String, WeekNumber As String, MyName As String

WeekNumber = Range("A1").Value
MyName = Range("A29").Value
FileName = "Time Sheet " & MyName & " - Week Ending " & Format$(Range("W5").Value, "yyyy-mm-dd")
ChDir _
txtPath.Value

ActiveWorkbook.SaveAs FileName:=FileName

The other thing I could do would be to have the file save to the folder that the file was opened from.

Sorry about the dumb questions, I haven?t touched vb6 in over 6 years.
Thanks for the help

Bob Phillips
07-14-2008, 01:10 AM
myDocs = CreateObject("WScript.Shell").SpecialFolders("MyDocuments")

mdmackillop
07-14-2008, 08:24 AM
FYI (http://vbaexpress.com/kb/getarticle.php?kb_id=762)

RyanT
07-15-2008, 03:48 PM
you guys are great, thank you