ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Function to Return File Name of Active Workbook (https://www.excelbanter.com/excel-programming/371269-function-return-file-name-active-workbook.html)

Magnivy

Function to Return File Name of Active Workbook
 
Hello,

I'm trying to create a custom function that would return the file name of
the active workbook (as I dont know a worksheet function that would do so
directly), and am not having much luck. I tried

Function filename()
filename = ActiveWorkbook.Name
End Function

but this returns an error. Any suggestions would be greatly appreciated.

Thank You!

Magnivy



Bob Phillips

Function to Return File Name of Active Workbook
 
=MID(CELL("filename",A1),FIND("[",CELL("filename",A1),1)+1,FIND("]",CELL("fi
lename",A1),1)-FIND("[",CELL("filename",A1),1)-1)

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Magnivy" wrote in message
...
Hello,

I'm trying to create a custom function that would return the file name of
the active workbook (as I dont know a worksheet function that would do so
directly), and am not having much luck. I tried

Function filename()
filename = ActiveWorkbook.Name
End Function

but this returns an error. Any suggestions would be greatly appreciated.

Thank You!

Magnivy





Jim Jackson

Function to Return File Name of Active Workbook
 
Sub filename()
MsgBox ("This Workbook's name is " & ThisWorkbook.Name)
End Sub

--
Best wishes,

Jim


"Magnivy" wrote:

Hello,

I'm trying to create a custom function that would return the file name of
the active workbook (as I dont know a worksheet function that would do so
directly), and am not having much luck. I tried

Function filename()
filename = ActiveWorkbook.Name
End Function

but this returns an error. Any suggestions would be greatly appreciated.

Thank You!

Magnivy



Jim Jackson

Function to Return File Name of Active Workbook
 
Sub filename()
MsgBox ("This Workbook's name is " & ThisWorkbook.Name)
End Sub

--
Best wishes,

Jim


"Magnivy" wrote:

Hello,

I'm trying to create a custom function that would return the file name of
the active workbook (as I dont know a worksheet function that would do so
directly), and am not having much luck. I tried

Function filename()
filename = ActiveWorkbook.Name
End Function

but this returns an error. Any suggestions would be greatly appreciated.

Thank You!

Magnivy



Magnivy

Function to Return File Name of Active Workbook
 
Jim, thanks for your reply. I am trying to create a function, insteat of a
macro, so that I would be able to use it inside a worksheet (as I need to use
the name of the file inside other functions). Is there a way to do that?

Thanks,
Magnivy

"Jim Jackson" wrote:

Sub filename()
MsgBox ("This Workbook's name is " & ThisWorkbook.Name)
End Sub

--
Best wishes,

Jim


"Magnivy" wrote:

Hello,

I'm trying to create a custom function that would return the file name of
the active workbook (as I dont know a worksheet function that would do so
directly), and am not having much luck. I tried

Function filename()
filename = ActiveWorkbook.Name
End Function

but this returns an error. Any suggestions would be greatly appreciated.

Thank You!

Magnivy



Magnivy

Function to Return File Name of Active Workbook
 
Thanks a lot for your help Bob!

"Bob Phillips" wrote:

=MID(CELL("filename",A1),FIND("[",CELL("filename",A1),1)+1,FIND("]",CELL("fi
lename",A1),1)-FIND("[",CELL("filename",A1),1)-1)

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Magnivy" wrote in message
...
Hello,

I'm trying to create a custom function that would return the file name of
the active workbook (as I dont know a worksheet function that would do so
directly), and am not having much luck. I tried

Function filename()
filename = ActiveWorkbook.Name
End Function

but this returns an error. Any suggestions would be greatly appreciated.

Thank You!

Magnivy







All times are GMT +1. The time now is 11:42 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com