ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   remove last part of string (https://www.excelbanter.com/excel-programming/331255-remove-last-part-string.html)

Mitch

remove last part of string
 
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?


Rob Bovey

remove last part of string
 
"Mitch" wrote in message
...
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



JE McGimpsey

remove last part of string
 
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", "")

In article ,
"Mitch" wrote:

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?



All times are GMT +1. The time now is 03:40 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com