PDA

View Full Version : Remembering a file path ...



vodkasoda
03-20-2009, 02:38 AM
A bit of a hypothetical question ... when I use the command ...

MyFixtures = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls), *.xls", Title:="Please Select Your Fixture File")

... I know that I can set the path in advance, so that the window will open wherever the file I want should be, as I've done that in a previous program that I've written ... however, if the program is going to be used on different machines, by different people, this path will always be different.

Is it possible to store the path that the user accesses the first time he runs the program, and then use that path the next time he uses the program, much like a cookie I suppose :think: ?!?

Bob Phillips
03-20-2009, 03:19 AM
You could store it in a defined name.

Something like



'-------------------------------------------------------------
Public Function GetPath() As String
'-------------------------------------------------------------
'On Error Resume Next
GetPath = Evaluate(ThisWorkbook.Names("FilePath").RefersTo)
End Function


'-------------------------------------------------------------
Public Function SetPath(ByVal path As String) As String
'-------------------------------------------------------------
ThisWorkbook.Names.Add Name:="FilePath", RefersTo:=path
End Function

vodkasoda
03-20-2009, 04:57 AM
Thanks,

I'll give this a try over the weekend ...



You could store it in a defined name.

Something like



'-------------------------------------------------------------
Public Function GetPath() As String
'-------------------------------------------------------------
'On Error Resume Next
GetPath = Evaluate(ThisWorkbook.Names("FilePath").RefersTo)
End Function


'-------------------------------------------------------------
Public Function SetPath(ByVal path As String) As String
'-------------------------------------------------------------
ThisWorkbook.Names.Add Name:="FilePath", RefersTo:=path
End Function