A family of Microsoft word processing software products for creating web, email, and print documents.
See my article on adding the date to the filename to use the current date.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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.
A family of Microsoft word processing software products for creating web, email, and print documents.
See my article on adding the date to the filename to use the current date.
AI answer
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^
05-Dec-2026 Trentham.docx if it is open.AddStakesToFileName.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.
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