Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a filename field without .doc extension in document header

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.

like image 471
Ben Avatar asked Oct 13 '10 06:10

Ben


People also ask

How do I insert filename in Word without extension?

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.

How do you insert the filename in the header?

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.

How do I insert filename in Excel without extension?

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.


2 Answers

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. alt text 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...):

  • insert filename without extension .doc using fields?
  • Inserting a File Name without an Extension
like image 66
Dennis G Avatar answered Oct 11 '22 18:10

Dennis G


add [Title] Instead of filename and maybe add some of the Other Document Properties Listed

like image 42
BigDogg Avatar answered Oct 11 '22 19:10

BigDogg