File Name as Cell Contents - Without File Extention

eilersca

New Member
Joined
May 5, 2002
Messages
7
Can you put the file name in a certain cell.

For Example:
File Name = C:My DocumentsContents.xls

In the contents.xls file, I would like cell D4 to equal the file name ("contents") without the full path and without the file extension. Same way that it can be display as a header.

lenze:

Your code:
Range("$A$1").Value=ActiveWorkbook.Name works, but Is there a way to remove the file extention (".xls") also?

Thanks for your help.

Chad
This message was edited by eilersca on 2002-05-07 09:01
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Try this:

=MID(CELL("filename",A1),FIND("[",CELL("filename",A1),1)+1,FIND("]",CELL("filename",A1),1)-FIND("[",CELL("filename",A1),1)-5)
 
Upvote 0
I knew I could find it:

Here:

This one returns the full path...

=SUBSTITUTE(SUBSTITUTE(LEFT(CELL("filename",A1),FIND("]",CELL("filename",A1))),"[",""),"]","")

This one returns just the filename...

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

Tom

_________________
Found a solution? If so, please post again so members of this board can spend their time helping others. Better still, edit your topic(intitial post), by tagging on a word or phrase such as, "Problem Solved", or "Resolved". Thanks for being courteous!
This message was edited by TsTom on 2002-05-07 08:27
 
Upvote 0
Use this code to place the name in a cell. Place code in the ThisWorkbook module

Private Sub Workbook_Open()
Range("$D$4").Value=ActiveWorkBook.Name
End Sub

This will place the file name in D4

Use this code for the header or footer

Private Sub Workbook_BeforePrint(Cancel As Boolean)
ActiveSheet.PageSetup.LeftFooter = ActiveWorkbook.Name
End Sub

Replace Name with FullName to include the path
 
Upvote 0
Here's another way.

Define a Name (let's call it wb) and type in the RefersTo box =GET.DOCUMENT(88)

Then to return the workbook name without the extension, type in any worksheet cell
=SUBSTITUTE(wb,".xls","")
 
Upvote 0

Forum statistics

Threads
1,214,572
Messages
6,120,306
Members
448,955
Latest member
Dreamz high

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