View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Jacob Skaria Jacob Skaria is offline
external usenet poster
 
Posts: 8,520
Default Filename str cut too short

It is removing the extension of activeworkbook and assigning that name to the
sheet name. If you already have a . (dot) it works wrongly.

Replace the below line

ActiveSheet.Name = Left(ActiveWorkbook.Name, Application.Find(".",
ThisWorkbook.Name) - 1)


with

ActiveSheet.Name = Left(ActiveWorkbook.Name, _
InStrRev(ActiveWorkbook.Name, ".") - 1)


If this post helps click Yes
---------------
Jacob Skaria


"Diddy" wrote:

Hi everyone,

I've nabbed this bit of code off the web and I'm using it with Chip
Pearson's code that loops through files in a folder to change the tab name
into the file name. All workbooks have only one sheet and code is working
fine except that it is cutting the filename too short. I don't understand how
the Left and -1 are working but think that the intention is to remove the
path and file extension.

If that's what the left and -1 are doing then why does the filename get
shortened?
Could any kind person please explain how this is working and show me how to
amend to give the unshortened filename without path and extension?

Thanks
Diddy

Sub renametabaswkbkname(myWB As Workbook)
On Error Resume Next
ActiveSheet.Name = Left(ActiveWorkbook.Name, Application.Find(".",
ThisWorkbook.Name) - 1)
myWB.Close savechanges:=True
End Sub