I am trying to return the file path of a specified file without the file name attached to the end of the path.
I am really struggling with interpreting the useless help documentation in VB.
I want the macro to prompt the user for a directory using this code..
pname = Application.GetOpenFilename(, , "Please Select A File In The Prefered Working Directory", , False)
This allows the user to browse the directories for the files they want but I really only want the directory, not the file itself. Unfortunately, you must select a file that gets attached to the variable, pname in this case.
This is one of the examples the help documentation shows for using the path property, one of the things that I tried...
Dim fs, d, f, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(filespec)
s = UCase(f.Path) & vbCrLf
s = s & "Created: " & f.DateCreated & vbCrLf
s = s & "Last Accessed: " & f.DateLastAccessed & vbCrLf
s = s & "Last Modified: " & f.DateLastModified
MsgBox s, 0, "File Access Info"
Can someone tell me what filespec stands for?
I don't care about the extra info, like date modified and such.
I am only concerned with getting the path to the directory that the user has chosen, without the filename.
I have tied countless different methods to extract the directory only without the file because my code goes on to use the
.LookIn command to search the designated directory for as many files of a certain type there are, then it opens each file one by one and does stuff to them.
I just don't want to have to hard code the path to the directory in the macro script. I want the user to be able to browse for it when they run the script.
Is there an easy way to do this that I am completely overlooking??