Remove .xls from selected files

  • Thread starter Thread starter Zurn
  • Start date Start date
Z

Zurn

With the code below I get a range of cells from different files and pu
it in a new file named globalbook

FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls)
*.xls", _
MultiSelect:=True)
...
For... ...
...
globalbook.Worksheets("X").Cells(r, 1).Value = insertbook.Name
r+1
...


The last line writes the name of each file on sheet X

My problem is that I don't need the *.xls * to be written on shee
X...*how can I easily trim the .xls from the filename?
 
Zurn,

Replace

insertbook.Name

with

Replace(insertbook.Name,".xls,"")

HTH,
Bernie
MS Excel MVP
 
globalbook.Worksheets("X").Cells(r, 1).Value =
Left(insertbook.Name,len(insertBook.Name)-4)

or

globalbook.Worksheets("X").Cells(r, 1).Value
=Application.Substitute(insertBook.Name,".xls","")

or use the VBA replace function in xl2000 and later instead of
Application.Substitute.
 
typo:

Replace(insertbook.Name,".xls,"")

should be


Replace(insertbook.Name,".xls","")

Note that the replace command was added in xl2000.

--
Regards,
Tom Ogilvy

Bernie Deitrick said:
Zurn,

Replace

insertbook.Name

with

Replace(insertbook.Name,".xls,"")

HTH,
Bernie
MS Excel MVP
 

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

Back
Top