Getting extension and file name from Variable Path

Ananthak275

Board Regular
Joined
Aug 22, 2020
Messages
128
Office Version
  1. 2013
Platform
  1. Windows
  2. MacOS
I have a path that I put into a variable. How would i make sure to get the file name and extension separately? I wanna be able to use this code for other variables that have a path extension with a file at the end.

Eg : Path_Extension = ("\\documents\data\file\datafile,xlsx")
Eg: Data_Extraction = ("\\desktop\sourcefile.xlsx")
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Maybe one of these options?

Book1 (version 1).xlsb
ABC
2\\documents\data\file\datafile.xlsxdatafile.xlsxdatafile.xlsx
3\\desktop/courcefle.xlsxdesktop/courcefle.xlsxdesktop/courcefle.xlsx
SalesOps
Cell Formulas
RangeFormula
B2:B3B2=RIGHT(A2,LEN(A2)-FIND("@",SUBSTITUTE(A2,"\","@",LEN(A2)-LEN(SUBSTITUTE(A2,"\",""))),1))
C2:C3C2=lastposition(A2,"\")


Code:
Function LastPosition(rCell As Range, rChar As String)
'This function gives the text from last position of the specified character to the end of string
'This code has been adapted from Sumit Bansal (https://trumpexcel.com)
Dim rLen As Integer
rLen = Len(rCell)
For i = rLen To 1 Step -1
If Mid(rCell, i - 1, 1) = rChar Then
 LastPosition = i
 LastPosition = Mid(rCell, i, rLen)
 Exit Function
End If
Next i
End Function
 
Upvote 0
Solution

Forum statistics

Threads
1,213,531
Messages
6,114,172
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top