remove last part of string

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?
 
R

Rob Bovey

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
 
J

JE McGimpsey

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", "")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top