Working in Office 2007, I'd like to add a filename field in my document header. The document will later be a PDF, so I don't want the extension.
I've played with Insert -> QuickParts -> Field, to no avail. I've got a gut feeling that it requires a formula...
Thanks in advance if you can help.
Another way to insert the file name without the extension is to use a different field. For instance, you could use File Properties to save the filename by typing it in manually without the extension. You could then use the DOCPROPERTY field to recall that specific property and insert it in your document.
Go to Insert > Header or Footer. Select Edit Header or Edit Footer. Select Quick Parts, and select Field. In the Field names list, choose the field you want (such as FileName, Date, Author, or Title), choose the format you want in the Field properties section.
Insert filename in cell without extension by Excel formula Select a blank cell, and enter the formula =TRIM(LEFT(SUBSTITUTE(MID(CELL("filename",A1),FIND("[",CELL("filename",A1))+1,255),". xl",REPT(" ",255)),255)) into it, and press the Enter key.
Your feeling is quite right.
Insert > QuickParts > Field > FileName
is the way to go, but as you see from the screenshot below, you do not have the option to turn the file extension on or off.
To show or not to show (Shakespearean style) the extension is purely up to the Windows Explorer setting to show or hide known file extensions. So, either you change that setting or you need some code.
A very simple Macro would be the following:
Sub InsertCurrentFileName()
Selection.InsertBefore Text:=Left(ActiveDocument.Name, Len(ActiveDocument.Name) - 4)
End Sub
What it does is simply strip the last 4 characters of the "Filename string" e.g. ".doc" - if you safe a ".docx" the "." would be preserved. Also this Macro would run once and you would need to run it again when the filename changes.
Maybe you could explain some more what you want to achieve with having the filename in the document header? Are you trying to use the filename in the document header to set some PDF property during conversion? Why not use the Document Title? Do you need the original filename in the PDF later - why?
Two more pages to help you with your problem (both relying on Macros...):
add [Title] Instead of filename and maybe add some of the Other Document Properties Listed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With