jasocke2
asked on
Got folder name from path, before filename (VBA)
Hi,
This should be quite a simple one.
If I have a variable (mypath) which is set to C:/Folder1/folder2/file.xl s in Excel VBA, what I want to do is extract the folder name before the file.xls which would be 'folder2'.
What VBA function could I use to get this and assign it to the variable 'MyFolder'?
Thanks,
This should be quite a simple one.
If I have a variable (mypath) which is set to C:/Folder1/folder2/file.xl
What VBA function could I use to get this and assign it to the variable 'MyFolder'?
Thanks,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Spot on thanks :)
Split the path into an array, and take the next to last member of the array:
MsgBox Split(mypath, "\")(UBound(Split(mypath, "\") - 1)
Regards,
Patrick