11

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 5

7

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.

8
  • By default, yes, it is exclusive mode and it does cause it to lock the file. There is some difference between exclusive and shared modes in how other users can access and modify the file using the same program, but I'm pretty sure that another program (ie explorer) would still locked out from accessing the file. I think shared mode is more specifically designed with oplocks in mind with multiple users over SMB, not on a local file system with different applications and the same user. I could be wrong though.
    – MaQleod
    Dec 12, 2012 at 4:31
  • @Karan - thanks, that's the type of answer I was looking for. So there's probably some underlying technical issue that prevents this from being implementing?
    – RoboShop
    Dec 12, 2012 at 9:42
  • Yes, the fact that Word (or any Office program) has exclusive access to the file is probably to prevent simultaneous updates to the same file from another program, leading to potential data loss. Preventing shared access is therefore most likely the best thing to do in this case, thus leading to the requirement that you need to release the lock on the file before you can perform any other operation on it.
    – Karan
    Dec 12, 2012 at 17:04
  • 1
    This should not be the selected answer as it discusses access by "other programs". The OP's request does not require such access.
    – kmote
    Jul 10, 2014 at 17:51
  • 1
    Regardless of locking, there's nothing stopping Word from having a File > Rename menu item that closes the file, renames it, and re-opens it for you under the covers, so you don't have to pop out to File Explorer. Jul 12, 2018 at 13:43
2

Yes, 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.)

1
  • 1
    This also works on Windows using <kbd>Ctrl</kbd> + click, opening a little popup where the filename is editable! Great tip, thanks @frisbee!
    – bdforbes
    May 5, 2020 at 22:54
2

Prompted 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.

1
  • Is there a way to enhance this macro so that file history is not lost? May 2, 2021 at 21:10
1

To 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
0

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
  • 4
    I doubt that's quite what the OP was looking for. Save As doesn't rename the file, it just saves a new copy under a different name. Dec 12, 2012 at 4:49
  • 6
    @Scandalist : what's with the sarcasm? I thought my question was fairly legitimate. I'm not saying it's a show stopper, I'm just saying that like all small tedious tasks, it requires time and brain power. Office suites are all about making you more productive, so from a user's perspective, I don't understand why it hasn't been implemented.
    – RoboShop
    Dec 12, 2012 at 9:39
  • @RoboShop, fair enough, if the real problem is productivity then you could quite easily write a macro and add it to the toolbar that prompts for a new file name, saves and closes the active document, renames the document and finally opens the renamed document. This achieves the task in hand with the "click of a button".
    – Adam
    Dec 14, 2012 at 13:22
  • this should be the right answer if one needs to rename a file while opening. Just save as the new name and then delete the old file
    – phuclv
    Nov 13, 2013 at 0:30
  • 1
    @RichLysakowskiPhD for the purposes expressed in the question, going from having one file with the former name to one file with the new name - that new file having all the history and other characteristics of the old one - is surely as close to equivalence as one needs. Note that with automatic cloud saves you need to save at start of a session of you want to keep the old version of the file without the most recent changes (which is slightly counterintuitive IMO, Word does warn about this behaviour FWIW).
    – pbhj
    Feb 18, 2022 at 17:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .