creating a filename function


Posted by Matt on December 14, 2000 8:15 AM

I'd like to create a function that will return the name
of the current workbook.

I've imagined that I'd do it by creating a simple function
with no argument.

Function filename()
'returns name of current workbook
filename = Workbook.???????
End Function

First, does anyone know the property name for the
name of the workbook?
Second, would this do what I want it to?

Thanks,
msnell

Posted by Joe on December 14, 2000 12:03 PM

Matt,
I haven't tested this, but how about
filename=activeworkbook.name

Joe

Posted by matt on December 14, 2000 3:16 PM

Works like a charm, Joe. Thanks

Any suggestion on how to lose the ".xls"?

-matt


Posted by Joe on December 15, 2000 8:41 AM


Matt,
Try
FileName = Left(ActiveWorkbook.Name, Application.Search(".", ActiveWorkbook.Name) - 1)

Joe



Posted by Tim Francis-Wright on December 15, 2000 8:50 AM

How's this?

Function filename()
Application.Volatile ' updates on recalculation
filename = ActiveWorkbook.Name
If Right(filename, 4) = ".xls" Then
filename = Left(filename, Len(filename) - 4)
End If
End Function

N.B.: there's a way to get this information
through the CELL("Filename",A1) function:
check out http://www.cpearson.com for more on this.