ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Return file from a path string (https://www.excelbanter.com/excel-programming/338072-re-return-file-path-string.html)

Bob Phillips[_6_]

Return file from a path string
 
One way Steph

Dim sFile
Dim ary

sFile = "C:\folder1\folder2\folder3\folder4\folder5\file.x ls"

ary = Split(sFile, "\")
MsgBox ary(UBound(ary))

or more directly, but less efficiently

Dim sFile

sFile = "C:\folder1\folder2\folder3\folder4\folder5\file.x ls"
MsgBox Split(sFile, "\")(UBound(Split(sFile, "\")))


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Steph" wrote in message
...
I have a string variable that is a path to a file:
C:\folder1\folder2\folder3\folder4\folder5\file.xl s

How can I create a new variable that is simply the file name.xls? Thanks!






All times are GMT +1. The time now is 01:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com