In this post, we will focus on presenting you with 2 smart ways to rename your document in Word quickly.
Now and then, while drafting in Word, we will constantly change the file name. Yet each time, we have to close the document before being able to renaming it. This is totally not convenient. By default, we can’t rename an open file. But with the help of a macro, it can be possible.
Following are 2 macros which can address such an issue.
Method 1: Rename a Document in Word
- First and foremost, press “Developer” tab then the “Visual Basic” to open Word VBA editor.
- Next click “Normal” project.
- Then click “Insert” and choose “Module”.
- Double click on the new module to open the coding area and paste the bellowing codes there:
Sub RenameDocument() Dim strDocName As String, strDocPath As String Dim strNewDocName As String Dim KillFile As String ' Get the current doc name. strDocName = ActiveDocument.FullName strDocPath = ActiveDocument.Path If strDocPath = "" Then MsgBox ("This document hasn't been saved. You can't rename it.") Exit Sub End If ' Pop up an input box for new name. strNewDocName = InputBox("Enter a new name for this document:", "Rename document", strDocName) ' Save the doc with newly entered name. ActiveDocument.SaveAs2 FileName:=strDocPath & "\" & strNewDocName ' Delete the doc with original name. KillFile = strDocName Kill KillFile End Sub
- Now click “Run” or hit “F5”.
- There will be an input box popping up. Just enter a new name in the text box and click “OK”.
Now the document will be stored in the same place with a new name. And running the macro shall delete the original file.
Method 2: Rename a Document and Append Date Information
In many cases, a document will be renamed with the date when revision is made. Under such circumstances, the main part of a file name remains the same only with a date string following. For example, here is a document without a date string.
In order to add it, we can run this macro:
Sub RenameDocumentWithDate() Dim strDocName, strDocNameNoExten, strDocFullName, strDocPath As String Dim strNewDocName As String Dim KillFile As String Dim strDate As String ' Get the current doc name. strDocName = ActiveDocument.Name strDocFullName = ActiveDocument.FullName strDocNameNoExten = Left(strDocName.Name, Len(strDocName.Name) - 5) strDocPath = ActiveDocument.Path strDate = Format(Date, "mm - dd - yyyy") If strDocPath = "" Then MsgBox ("This document hasn't been saved. You can't rename it.") Exit Sub End If ' Save the doc in new name with date. ActiveDocument.SaveAs2 FileName:=strDocPath & "\" & strDocNameNoExten & " " & strDate KillFile = strDocFullName Kill KillFile End Sub
You can follow the exact steps in method 1 to install and run the above macro. It shall work beautifully. You will see the current date string is following after the original name, such as bellow:
Solution to Word Document Corruption
We can’t prevent document corruption from happening with a once for all method. What we can do is to take backups and avoid user errors as possible as we can. One of the most important points is to get familiar with what to do after a doc gets corrupt. The right answer is to obtain a doc recovery tool as soon as possible.
Author Introduction:
Vera Chen is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including Excel damage and pdf repair software products. For more information visit www.datanumen.com