Using some VBA, I am able to select a file. I need to get the directory path of that selected file without the file name.
The answer seems to be right in front of me but I am missing something.
Here is the code I am using:
The selected file will always be a .xlsx file.
Example: File selected: C:\Folder\Where\File\Is\Located\File.xlsx
I need: C:\Folder\Where\File\Is\Located\
Seems it should be quite simple, but the solution eludes me.
Any thoughts/suggestions?
-Spydey
P.S. I realize that "MsgBox sPath w/out file name" isn't going to give me the directory path. That is just an example of what I hope to have the msgbox output.
The answer seems to be right in front of me but I am missing something.
Here is the code I am using:
Code:
Private Sub PickFile()
Dim fd As FileDialog
Dim sPath As String
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.Title = "Select file"
If fd.Show <> -1 Then MsgBox "No file selected! Exiting script.": End
sPath = fd.SelectedItems(1)
End With
MsgBox sPath w/out file name
End Sub
The selected file will always be a .xlsx file.
Example: File selected: C:\Folder\Where\File\Is\Located\File.xlsx
I need: C:\Folder\Where\File\Is\Located\
Seems it should be quite simple, but the solution eludes me.
Any thoughts/suggestions?
-Spydey
P.S. I realize that "MsgBox sPath w/out file name" isn't going to give me the directory path. That is just an example of what I hope to have the msgbox output.
Last edited: