PDA

View Full Version : File name in cell



sukumar.vb
09-02-2011, 03:58 AM
In VBA, how can we write file name excluding extension of file?

omp001
09-02-2011, 05:05 AM
Hi.
Can it be by a UDF?

Function MyName() As String
MyName = ThisWorkbook.Name
End Function
in a blank cell type =MyName()

Bob Phillips
09-02-2011, 05:37 AM
Left$(Activeworkbook.Name,InstrRev(Activeworkbook.Name,".")-1)

sukumar.vb
09-02-2011, 06:47 AM
Worksheets("Sheet1").Range("A1").Value = Workbooks("C:\Work.xls").Worksheets("Sheet1").Range("A1").Value



This program gave an error :
Subscript out of range.

What is your opinion?

Bob Phillips
09-02-2011, 08:34 AM
My opinion? What does this have to do with the question you first asked?

sukumar.vb
09-02-2011, 11:43 AM
My opinion? What does this have to do with the question you first asked?

Sorry, I should have posted it as a new post.

Kenneth Hobs
09-03-2011, 03:49 PM
Worksheets("Sheet1").Range("A1").Value = _
CreateObject("Scripting.FileSystemObject").GetBaseName(thisworkbook.FullName)