Filename Function

gdesreu

Active Member
Joined
Jul 30, 2012
Messages
318
Does anyone have a function to grab the filename and extension without the filepath? I found this formula but I think a function would be a lot easier
VBA Code:
=MID(CELL("filename",A1),FIND("[",CELL("filename",A1))+1,FIND("]", CELL("filename",A1))-FIND("[",CELL("filename",A1))-1)
Thanks
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
There is not a single function that can do that, at least for now.

Do you mean a User Defined Function (UDF)

maybe
VBA Code:
Function Wkbname() As String
    Wkbname = ThisWorkbook.Name
End Function
 
Upvote 0
There is not a single function that can do that, at least for now.

Do you mean a User Defined Function (UDF)

maybe
VBA Code:
Function Wkbname() As String
    Wkbname = ThisWorkbook.Name
End Function
Yes I meant UDF. How would you call the function? wkbname() returns the module name and not the actual name of the workbook. - Thanks
 
Upvote 0
I. Open VBA (using ALT+F11
2. Insert a Module (AlT+I+M), ensure you are inserting in the appropriate workbook, you can look at the project explorer on the left in the VBE to be certain
3. Paste the lines of code in there

You should then be able to use the function like =Wkbname() in the worksheet
 
Upvote 0
I. Open VBA (using ALT+F11
2. Insert a Module (AlT+I+M), ensure you are inserting in the appropriate workbook, you can look at the project explorer on the left in the VBE to be certain
3. Paste the lines of code in there

You should then be able to use the function like =Wkbname() in the worksheet
OK my bad, I forgot to add that I process a lot of files daily and I was hoping to add this to an xlam file so that I can use it on any excel file I am in. - Thanks, sorry I didnt mention that.
 
Upvote 0
If the macro is saved your PersonalMacroWorkbook, it should be available to all workbooks.

You can Record a samole macro and choose to store in the "personal Macro Workbook" thereby creating the Personal macro Workbook, after which you can proceed to dump the code in there(you should see the workbook in the VBE in the Project Explorer)

That should work
 
Upvote 0
If the macro is saved your PersonalMacroWorkbook, it should be available to all workbooks.

You can Record a samole macro and choose to store in the "personal Macro Workbook" thereby creating the Personal macro Workbook, after which you can proceed to dump the code in there(you should see the workbook in the VBE in the Project Explorer)

That should work
ok thanks I will give that a try!
 
Upvote 0
If the macro is saved your PersonalMacroWorkbook, it should be available to all workbooks.

You can Record a samole macro and choose to store in the "personal Macro Workbook" thereby creating the Personal macro Workbook, after which you can proceed to dump the code in there(you should see the workbook in the VBE in the Project Explorer)

That should work
Thanks for your help. I was able to get what I wanted by using this UDF in the xlam file. I changed it from "thisworkbook" to "activeworkbook"
VBA Code:
Function Getname() As String
    Getname = ActiveWorkbook.Name
End Function
 
Upvote 0
Thanks for your help. I was able to get what I wanted by using this UDF in the xlam file. I changed it from "thisworkbook" to "activeworkbook"
VBA Code:
Function Getname() As String
    Getname = ActiveWorkbook.Name
End Function
Many ways to skin a cat...

If you use Thisworkbook, it would refer to .xlam as opposed to the actual workbook, so that switch was necessary. Well done
 
Upvote 0
Many ways to skin a cat...

If you use Thisworkbook, it would refer to .xlam as opposed to the actual workbook, so that switch was necessary. Well done
Thanks again, you gave me the structure I needed to see how it was done. This should save me quite a bit of time. Have a nice day.
 
Upvote 0

Forum statistics

Threads
1,215,425
Messages
6,124,825
Members
449,190
Latest member
rscraig11

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top