Word I want to file to add text "Stakes"

SteveD 865 Reputation points
2026-12-04T20:32:12.6166667+00:00

Hello from Steve

In file C:\Racing, I have a document called 05-Dec-2026 Trentham

Objective please is to open C:\Racing and add to 05-Dec-2026 Trentham

I want to type Stakes

First document End result 05-Dec-2026 Trentham

Saveas Second document End result 05-Dec-2026 Trentham Stakes I have several documents.

Microsoft 365 and Office | Word | For home | Windows
0 comments No comments

Answer accepted by question author
Charles Kenyon 172.8K Reputation points Volunteer Moderator
2026-12-04T22:17:55.91+00:00

Was this answer helpful?

1 person found this answer helpful.

Answer accepted by question author

AI answer

2026-12-04T20:32:57.88+00:00

Close the document, then run this Word VBA macro to rename 05-Dec-2026 Trentham.docx as 05-Dec-2026 Trentham Stakes.docx without changing its contents.

Sub AddStakesToFileName()

    Dim oldName As String
    Dim newName As String

    oldName = "C:\Racing\05-Dec-2026 Trentham.docx"
    newName = "C:\Racing\05-Dec-2026 Trentham Stakes.docx"

    If Dir(oldName) = "" Then
        MsgBox "The original document was not found."
    ElseIf Dir(newName) <> "" Then
        MsgBox "A document with the new name already exists."
    Else
        Name oldName As newName
        MsgBox "File renamed successfully."
    End If

End Sub

The VBA Name statement renames an existing disk file. The document must be closed before the statement runs, and the new filename must not already exist. ^1^

Run the macro

  1. Close 05-Dec-2026 Trentham.docx if it is open.
  2. In Word, press Alt+F11.
  3. Select Insert → Module.
  4. Paste the code into the module.
  5. Click anywhere inside AddStakesToFileName.
  6. Press F5.

The resulting file will be:

C:\Racing\05-Dec-2026 Trentham Stakes.docx

If the actual extension is .docm or .doc rather than .docx, change the extension on both the oldName and newName lines. Keep the same extension so the document format is not changed.

If the document must remain open

Use Word’s SaveAs2 method instead. It saves the document under a new name and can accept the complete path. ^2^

Sub AddStakesToOpenDocument()

    ActiveDocument.SaveAs2 _
        FileName:="C:\Racing\05-Dec-2026 Trentham Stakes.docx", _
        FileFormat:=wdFormatXMLDocument

End Sub

This creates the new filename through Save As rather than directly renaming the closed file.


References

  1. Name statement
  2. Document.SaveAs2 method (Word)
AI-generated content may be incorrect. Read our transparency notes for more information.

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Oldest

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.