remove last part of string

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to create a text string from a variable length file name by removing
the .xls from the end of the file name. It would be easy if the file names
were a fixed length, but they are not. Is there another easy way?
 
Mitch said:
I need to create a text string from a variable length file name by removing
the .xls from the end of the file name. It would be easy if the file
names
were a fixed length, but they are not. Is there another easy way?

Hi Mitch,

Here's one way to do it:

Dim szFilename As String
Dim szNameOnly As String
szFilename = "My File Name.xls"
szNameOnly = Left$(szFilename, Len(szFilename) - 4)

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm
 
One way:

sFileName = Left(sFileName, Len(sFileName) - 4)

or, if you weren't sure whether the extension was there or not:

sFileName = Replace(sFileName, ".xls", "")
 
Back
Top