Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Extract Name from File Path
Hi all, in cell A1 i have file path as below
C:\Documents and Settings\My Documents\Tests\Test1\Simon Brown.txt and i got macro on a button (see below) Sub Button1_Click() cv = Range("a1").Value Range("a3").Value = Right(cv, Len(cv) - InStrRev(cv, "\")) End Sub I get result "Simon Brown.txt" in cell A3 but i just need result "Simon Brown". So please can anyone help that what changes i should do in my macro above which should get rid of any thing after dot like .txt and just give the person name like "Simon Brown" |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Extract Name from File Path
Hi
This should do it: cv = Range("a1").Value cv = Right(cv, Len(cv) - InStrRev(cv, "\")) Range("A3") = Left(cv, InStr(cv, ".") - 1) Regards, Per "K" skrev i meddelelsen ... Hi all, in cell A1 i have file path as below C:\Documents and Settings\My Documents\Tests\Test1\Simon Brown.txt and i got macro on a button (see below) Sub Button1_Click() cv = Range("a1").Value Range("a3").Value = Right(cv, Len(cv) - InStrRev(cv, "\")) End Sub I get result "Simon Brown.txt" in cell A3 but i just need result "Simon Brown". So please can anyone help that what changes i should do in my macro above which should get rid of any thing after dot like .txt and just give the person name like "Simon Brown" |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Extract Name from File Path
That code will work as long as the filename does, in fact, have an
extension. Here is some alternate code which will work whether the filename has an extension or not... cv = Range("A1").Value Range("A3").Value = Split(Split(cv, "\")(UBound(Split(cv, "\"))), ".")(0) -- Rick (MVP - Excel) "Per Jessen" wrote in message ... Hi This should do it: cv = Range("a1").Value cv = Right(cv, Len(cv) - InStrRev(cv, "\")) Range("A3") = Left(cv, InStr(cv, ".") - 1) Regards, Per "K" skrev i meddelelsen ... Hi all, in cell A1 i have file path as below C:\Documents and Settings\My Documents\Tests\Test1\Simon Brown.txt and i got macro on a button (see below) Sub Button1_Click() cv = Range("a1").Value Range("a3").Value = Right(cv, Len(cv) - InStrRev(cv, "\")) End Sub I get result "Simon Brown.txt" in cell A3 but i just need result "Simon Brown". So please can anyone help that what changes i should do in my macro above which should get rid of any thing after dot like .txt and just give the person name like "Simon Brown" |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How to extract only file name from folder path string in Excel? | Excel Worksheet Functions | |||
extract path from FullName | Excel Programming | |||
How to extract data from File Path | Excel Programming | |||
Formula too long - new file path is shorter than old file path - Excel 2003 | Excel Worksheet Functions | |||
Extract Path From String | Excel Programming |