Function to Return File Name of Active Workbook

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
=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)
 
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
 
Thanks a lot for your help Bob!

Bob Phillips said:
=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 said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top