Use a Word Table Field as the Default Save As File Name
Question details
Suggest a file name based on a person's name entered in a Word table cell.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- A user fills in a name in a table and wants to use it when saving the document.
- Observed behavior
- The Save As dialog should suggest a file name derived from the table cell.
Identify the table number and the row and column containing the name. Check whether recipients can run trusted macros, since Word security settings may block them.
Use a Word macro to suggest a file name from a table cell
Run a macro that reads the name, cleans it for use as a file name, and opens the Save As dialog.
This macro uses the first table and cell in row 2, column 2. Change those numbers to match your document. It suggests a name when you run the macro; it does not change Word's normal Save As behavior.
In Word, open the document and select Developer > Visual Basic. If the Developer tab is hidden, enable it in Word's ribbon settings.
In the VBA editor, select the document or its template in the project pane, choose Insert > Module, and paste this code: Sub SaveUsingTableName() Dim personName As String Dim badChar As Variant Dim i As Integer Dim saveDialog As Dialog On Error GoTo TableError personName = ActiveDocument.Tables(1).Cell(2, 2).Range.Text On Error GoTo 0 For i = 0 To 31 personName = Replace(personName, Chr(i), " ") Next i For Each badChar In Array("\", "/", ":", "*", "?", Chr(34), "<", ">", "|") personName = Replace(personName, badChar, "-") Next badChar personName = Trim(personName) Do While Len(personName) > 0 If Right(personName, 1) <> "." And Right(personName, 1) <> " " Then Exit Do personName = Left(personName, Len(personName) - 1) Loop If Len(personName) = 0 Then MsgBox "Enter a name in the table cell first." Exit Sub End If Set saveDialog = Dialogs(wdDialogFileSaveAs) saveDialog.Name = "Person - " & Left(personName, 80) saveDialog.Show Exit Sub TableError: MsgBox "Check the table, row, and column numbers in the macro." End Sub
Select File > Save As and save the document as a Word Macro-Enabled Document (.docm), or store the macro in a macro-enabled template. A standard .docx file cannot retain VBA macros.
Enter the person's name in the configured cell, then select View > Macros, choose SaveUsingTableName, and select Run. Review the suggested name, location, and file type in the Save As dialog before selecting Save.

Edit Word Documents in WPS Writer
WPS Writer is a free, lightweight alternative with a familiar interface for editing Word documents. Open compatible files and continue working in a similar layout as you move between office suites; the Word VBA solution above is not a fix provided by WPS.

Frequently Asked Questions
Will Word automatically use a table cell as the file name?
Not normally. Run the macro through View > Macros to suggest a name from the configured cell in the Save As dialog.
How do I select a different cell for the file name?
In the VBA editor, change Tables(1).Cell(2, 2) to the appropriate table number, row, and column. For example, Cell(3, 1) reads row 3, column 1.
Why does the macro not run for another user?
Their Word macro security settings may block or disable it. Distribute macro-enabled files carefully, and ask users to enable macros only if they trust the document and its source.
Can I keep the macro in a DOCX file?
No. Save it in a macro-enabled .docm document or a macro-enabled template. Check the file type in the Save As dialog before saving a copy.




