View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Matthew Herbert Matthew Herbert is offline
external usenet poster
 
Posts: 56
Default Filename str cut too short

On Aug 3, 11:20*am, 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


Diddy,

You may want to start by reading the help file on the LEFT and FIND
functions. (Insert a function, search for LEFT (and FIND), then
select "Help on this function", and read the file). This will give
you a good background of what these functions do. The biggest
question I would have is this: Does your file name have "." in them
other than the "." prior to the file extension? If the answer is yes,
then after you read about FIND and LEFT, you'll know why the procedure
isn't working to your liking. ActiveWorkbook.Name will return the
file name with the extension, e.g. Prototype Analysis Tool
(2007-08-03) v9.xlsm. Again, start with LEFT and FIND. If you have a
question after this, then reply again to the post.

Best,

Matthew Herbert