Getting extension and file name from Variable Path

Ananthak275

Board Regular
Joined
Aug 22, 2020
Messages
55
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

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

kweaver

Well-known Member
Joined
May 8, 2018
Messages
2,134
Office Version
  1. 365
  2. 2010
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
 
Solution

Forum statistics

Threads
1,147,518
Messages
5,741,634
Members
423,674
Latest member
Charles2dodo

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
Top