Share via

Automatically Update File "Title" with "Filename"? (Or Publish as PDF Default)

Anonymous
2025-06-10T17:57:39+00:00

I essentially have two questions related to the Title of Word documents. I create countless documents from a single template, and I would like to be able to automatically update the new document's "Title" with its new "Filename." This is because when I Publish as PDF before distributing the document, the Title of the new PDF carries over from the original Word document.

So the first option is to somehow set up my Word such that the Title is always the Filename of the document. (I would be open to adjusting Macros, but I have never done that before.)

And if that cannot be done (or, in addition to), is there a way to set the default Options when I "Publish as PDF"? I am finding that if I click "Publish to PDF," navigate to "Options," and uncheck "Document Properties," the title of the resulting PDF will simply be the file name. That is what I want. But I do not know how to change that Option to be a default with every PDF I create; I would rather not have to go through those extra steps each time.

Either of these would be a great help to me. Thanks!

Microsoft 365 and Office | Word | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

  1. Charles Kenyon 166.8K Reputation points Volunteer Moderator
    2025-06-11T09:05:23+00:00

    what "hook it to the DocumentBeforeSave event via ThisDocument" references.)

    Your explanation is quite detailed, and I appreciate the ease of copying and pasting code -- I am just not sure I know what to do with it. "> Thanks so much for taking time to reply, Kristen! I appreciate you taking the time in sharing your suggestions. Unfortunately, I tried to create these Macros and I just couldn't get them to work. I am not familiar with saving .dotm vs .docx files, and am not sure if I saved the Macros correctly.

    (I am also not certain what "hook it to the DocumentBeforeSave event via ThisDocument" references.)

    Your explanation is quite detailed, and I appreciate the ease of copying and pasting code -- I am just not sure I know what to do with it.

    To hold macros, a file must be saved as a .dotm or .docm file type.

    A template is a file used to create new documents that will have the resources of the template.

    Templates in Microsoft Word (https://www.addbalance.com/usersguide/templates.htm)

    2 people found this answer helpful.
    0 comments No comments

7 additional answers

Sort by: Most helpful
  1. Anonymous
    2025-06-10T20:18:24+00:00

    Thanks so much for taking time to reply, Kristen! I appreciate you taking the time in sharing your suggestions. Unfortunately, I tried to create these Macros and I just couldn't get them to work. I am not familiar with saving .dotm vs .docx files, and am not sure if I saved the Macros correctly.

    (I am also not certain what "hook it to the DocumentBeforeSave event via ThisDocument" references.)

    Your explanation is quite detailed, and I appreciate the ease of copying and pasting code -- I am just not sure I know what to do with it.

    0 comments No comments
  2. Anonymous
    2025-06-10T20:12:10+00:00

    Thanks for responding, Charles. I just created a dummy file and inserted the Title "box" in the document and saved it. While it did change the Title, that did not "use that property to create the file name." I am guessing I may have missed a step between putting the Content Control box in the file -- and having that information appear as the file name?

    0 comments No comments
  3. Charles Kenyon 166.8K Reputation points Volunteer Moderator
    2025-06-10T19:25:51+00:00

    If you, in your template, include the Title document property Content Control, you can type your filename without the .docx extension in that control in new documents.

    This changes the Title Document Property, itself.

    By default, when you save the new document, Word will use that property to create the file name.

    0 comments No comments
  4. Anonymous
    2025-06-10T19:21:22+00:00

    Hi Jeremy,

    Thank you for reaching out to Microsoft Community. We're happy to help you with your concern. 

    It's a frequent workflow pain when Word's built-in document properties, especially the Title, get unintentionally reused in PDFs exported from templates. Let's walk through both of your questions with clear solutions:

    Goal 1: Automatically Set Word Document "Title" to Match Filename

    • Word stores the "Title" in File > Info > Properties, and this gets embedded in exported PDFs unless removed.
    • To automatically update the Title to match the Filename, you can use a simple VBA macro:

    Macro: Set Title = Filename

    Sub UpdateTitleWithFilename()
        Dim doc As Document
        Set doc = ActiveDocument
    
        ' Get filename without extension
        Dim fileName As String
        fileName = Left(doc.Name, InStrRev(doc.Name, ".") - 1)
    
        ' Update the Title property
        doc.BuiltInDocumentProperties("Title").Value = fileName
    End Sub
    

    To Set This Up:

    1. Press Alt + F11 in Word to open the VBA editor.
    2. Insert → Module.
    3. Paste the macro above.
    4. Save the macro-enabled template as .dotm (so it works for new documents).
    5. (Optional) You can even call this macro on document save or export for automation.

    If you want to automate this every time you save the document, you can hook it to the DocumentBeforeSave event via ThisDocument or create a macro-enabled template that includes this logic.

    Goal 2: PDF Export Without Using "Title" Metadata (Use Filename Instead)

    You're absolutely right — when exporting a Word doc to PDF:

    • If File > Info > Properties > Title is filled, that gets used as the PDF title.
    • If you uncheck “Document properties” in the export dialog, the PDF uses the filename instead.

    There's no built-in Word setting to make “exclude document properties” the default.

    Workaround: Export via Macro with Correct Settings

    Here’s a macro that exports to PDF and automatically unchecks “Document Properties”:

    Sub ExportToPDF_WithoutProperties()
        Dim filePath As String
        filePath = ActiveDocument.Path & "\" & _
                   Left(ActiveDocument.Name, InStrRev(ActiveDocument.Name, ".") - 1) & ".pdf"
    
        ActiveDocument.ExportAsFixedFormat OutputFileName:=filePath, _
            ExportFormat:=wdExportFormatPDF, _
            OpenAfterExport:=False, _
            OptimizeFor:=wdExportOptimizeForPrint, _
            Range:=wdExportAllDocument, _
            Item:=wdExportDocumentContent, _
            IncludeDocProps:=False, _
            KeepIRM:=True, _
            CreateBookmarks:=wdExportCreateHeadingBookmarks, _
            DocStructureTags:=True, _
            BitmapMissingFonts:=True, _
            UseISO19005_1:=False
    End Sub
    

    I hope these solutions can help you to solve this issue. Please know that we truly appreciate your patience and understanding as we work to support you. If you need any further assistance or clarification, feel free to reach out - we're here to help. 

    Best regards,   

    Kristen - L - MSFT | Microsoft Community Support Specialist.

    0 comments No comments