Answers:
Word以独占模式 AFAIK 打开文档,因此这会锁定文件并阻止其他程序访问,直到通过关闭文件或Word本身释放锁定为止。我不认为提供对文档的共享访问是一个可行的解决方案,否则如果有意义的话,肯定会很久就实现。
在@Adam和@LưuVĩnhPhúc的建议的推动下,我创建了以下宏,可以满足您的要求。请注意,这将删除与该文件关联的任何历史记录。
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
*注意:虽然此宏适用于Powerpoint(上面提到的修改),但PowerPoint 无法全局保存。
微软已经在最新的Word中加入了突破性的新功能,旨在满足您的确切需求 -
单击文件,然后单击“另存为”