I just ask this question as I do not believe that after so many versions of Word, it wouldn't exist.
Usually when I'm working on a document and I realize I have to rename it, I have to close the document down, go to file explorer and then rename it, and then opening it up again.
It's a procedure that's so ingrained in my usage pattern that I didn't realize until now that I'm actually having to open and close multiple windows/ applications etc. simply to rename a file. Surely, it's the year 2012, I should be able to do a simple thing like that with a few clicks right?
So is there a way to just rename the file name of a word /excel / office document without having to close it first?
5 Answers
Word opens documents in exclusive mode AFAIK, so this locks the files and prevents access by other programs until the lock is released by closing the files or Word itself. I don't think providing shared access to documents is a workable solution, otherwise it would surely have been implemented long back if it made sense.
8Yes, it's possible!
At least on a Mac (OS X 10.8.5). Just Cmd + click on the file name on top of your opened Office document, that you want to rename. You then see the path where the file is located. Next you click on the name of the folder directly under the file name. The name then appears in a Finder screen, where you can adjust its name to whatever you want.
So no need to first close the file, nor to use 'save as' and removing the first file from the finder! (I don't know if the same or similar trick works out in Windows.)
1Prompted by the suggestions of @Adam and @Lưu Vĩnh Phúc, I created the following macro that does what you requested. Note that this will delete any history associated with the file.
Sub RenameActiveFile() ' ' Renames the current file without closing the document (assuming file has already been saved) ' (Actually, saves with new name and deletes previous, so history will be lost). ' Dim strFileFullName, strFileName, strNewName As String Dim res As VbMsgBoxResult ' Get current name: strFileFullName = ActiveDocument.FullName 'for Word docs 'strFileFullName = ActiveWorkbook.FullName 'for Excel docs 'strFileFullName = Application.ActivePresentation.FullName 'for Powerpoint presentations* If (InStr(strFileFullName, ".") = 0) Then res = MsgBox("File has not been saved. Can't rename it.", , "Rename File") Exit Sub End If strFileName = Right(strFileFullName, Len(strFileFullName) - InStrRev(strFileFullName, "\")) 'strip path strFileName = Left(strFileName, (InStr(strFileName, ".") - 1)) ' strip extension ' Prompt for new name: strNewName = InputBox("Rename this file to:", "Rename File", strFileName) If (strNewName = "") Or (strNewName = strFileName) Then ' (Check whether user cancelled) Exit Sub End If ' Save file with new name: ActiveDocument.SaveAs2 FileName:=strNewName 'for Word docs 'ActiveWorkbook.SaveAs2 FileName:=strNewName 'for Excel docs 'Application.ActivePresentation.SaveAs FileName:=strNewName 'for Powerpoint presentations* ' Delete old file: With New FileSystemObject ' (this line requires: Tools->References->Microsoft scripting runtime) If .FileExists(strFileFullName) Then .DeleteFile strFileFullName End If End With
End Sub*Note: although this macro works with Powerpoint (with modifications noted above), PowerPoint can't save it globally.
1To answer the need of Rich Lysakowski (and mine too), here is a different approach which preserves history! (it actually closes and reopens the file)
Sub RenameActiveFile() Dim strFileFullName, strFilePath, strFileName, strFileExt, strNewName, strNewFullName As String Dim result As VbMsgBoxResult 'check if it is a new file which has never been saved If ActiveDocument.Path = "" Then On Error Resume Next 'to avoid VBA error if cancel is pressed ActiveDocument.Save Exit Sub End If ' Get current name: strFileFullName = ActiveDocument.FullName 'for Word docs strFilePath = ActiveDocument.Path 'Left(strFileFullName, InStrRev(strFileFullName, "\")) strFileName = Left(ActiveDocument.Name, (InStrRev(ActiveDocument.Name, ".") - 1)) ' strip extension strFileExt = Mid(ActiveDocument.Name, (InStrRev(ActiveDocument.Name, ".") + 1)) 'get extension If Not (ActiveDocument.Saved) Then result = MsgBox("""" & strFileName & """ needs to be saved before renaming." & vbCrLf & "Save """ & strFileName & """ ?" & strNewName, _ vbQuestion + vbYesNo, "Document not saved") If result = vbNo Then Exit Sub ActiveDocument.Save End If ' Prompt for new name: strNewName = InputBox("Rename """ & strFileName & """ to:" & vbCrLf & "(do not type extension: ""." & strFileExt & """ will be added)", _ "Rename File", strFileName) 'Check whether user cancelled If (strNewName = "") Or (strNewName = strFileName) Then Exit Sub Else strNewFullName = strFilePath & "\" & strNewName & "." & strFileExt End If 'check if new name exist (not working with online files) If Dir(strNewFullName) > "" Then result = MsgBox("A file """ & strNewName & """ already exist in the same folder!", vbExclamation, "Renaming failed") Exit Sub End If 'close, rename and reopen file ActiveDocument.Close Name strFileFullName As strNewFullName Documents.Open FileName:=strNewFullName
End Sub Microsoft has included ground breaking new features in the latest Word designed to accommodate those with your exact concerns -
Click file and then 'Save As'
7