乔山办公网我们一直在努力
您的位置:乔山办公网 > word文档 > 如何快速给大量word文件重<em>命名</em>?-批量word 命名,word怎么批量命名

如何快速给大量word文件重<em>命名</em>?-批量word 命名,word怎么批量命名

作者:乔山办公网日期:

返回目录:word文档


这里有个小软件,主要用于批量更换标题名到文件名,使其zhidao一致。
软件自动查找Office文档中的标题名,并与文档名比较,不同就以标题名改之。可以批量更改文件名为标题。

下载地址: http:///Soft/softdown.asp?softid=16535

可以用脚本来做。

1、用记事本新建一个文本文件,把它保存为“批量重命名.vbs”(注意不要弄成了“批量重命名.vbs.txt”,也就是要确保其扩展名为“.vbs”);
2、把下列代码粘贴到这个VBS文件中:
Option Explicit
Const g_strRootPath = "c:\Temp\docs\Word\ToRename\" ' 指定存放所有文件的目录,可以有子目录
Const g_nTitleMaxLen = 16 ' 指定获取文档里面第一段中的前多少个字符来作为文件名
Call Main
' 主函数入口
Sub Main()
Dim fso, oFolder, oWordApp
Set oWordApp = CreateObject("Word.Application")
Set fso = CreateObject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder(g_strRootPath)
RenameDocFilesUnderFolder oWordApp, fso, oFolder
oWordApp.Quit
Set oWordApp = Nothing
MsgBox "完成!"
end Sub
' 重命名指定文件夹(递归)下面的所有Word文件,按照文件里面的第一句可见的文字命名
Sub RenameDocFilesUnderFolder(oWordApp, fso, oFolder)
Dim oSubFolder, oFile, oDoc
Dim strTitle, strFileName
For Each oSubFolder In oFolder.SubFolders
RenameDocFilesUnderFolder oWordApp, fso, oSubFolder
next
For Each oFile In oFolder.Files
Set oDoc = oWordApp.Documents.Open(oFile.Path)
strTitle = GetFirstVisibleTextContent(oDoc)
oDoc.Close
Set oDoc = Nothing
If Len(strTitle) <> 0 Then
strFileName = fso.BuildPath(fso.GetParentFolderName(oFile.Path), strTitle & "." & fso.GetExtensionName(oFile.Path))
strFileName = GetUniqueFileName(fso, strFileName)
fso.MoveFile oFile.Path, strFileName
end If
next
end Sub
' 获取指定文档第一行可见文字
Function GetFirstVisibleTextContent(oDoc)
Dim oParagraph
Dim strContent
For Each oParagraph In oDoc.Paragraphs
strContent = GetSafeFileName(oParagraph.Range.Text)
If Len(strContent) <> 0 Then
GetFirstVisibleTextContent = strContent
Exit Function
end If
next
GetFirstVisibleTextContent = ""
end Function
' 过滤文件名里面的无效字符
Function GetSafeFileName(strFileName)
Dim arrUnsafeCharacters, strUnsafeChar
Dim nIndex
arrUnsafeCharacters = Array("\", "/", ":", "*", "?", """", "<", ">", "|")
For nIndex = 0 To &H2F
strFileName = Replace(strFileName, Chr(nIndex), "")
next
For Each strUnsafeChar In arrUnsafeCharacters
strFileName = Replace(strFileName, strUnsafeChar, "")
next
GetSafeFileName = left(Trim(strFileName), g_nTitleMaxLen)
end Function
' 获取不重复的文件名,如果有重名则在文件名后面附加“_1”、“_2”……
Function GetUniqueFileName(fso, strFullName)
Dim strParentFolder, strBaseName, strExtensionName
Dim nIndex
If Not fso.FileExists(strFullName) Then
GetUniqueFileName = strFullName
Exit Function
end If
strParentFolder = fso.GetParentFolderName(strFullName)
strBaseName = fso.GetBaseName(strFullName)
strExtensionName = fso.GetExtensionName(strFullName)
nIndex = 0
While fso.FileExists(strFullName)
nIndex = nIndex + 1
strFullName = fso.BuildPath(strParentFolder, strBaseName & "_" & nIndex & "." & strExtensionName)
Wend
GetUniqueFileName = strFullName
End Function

3、修改代码中e799bee5baa6e79fa5e98193e4b893e5b19e333开始部分的两个设置,即:存放等待重命名的Word文件的根目录,以及获取文档第一段内容时最多保留多少个字符。
4、保存这个VBS文件,在资源管理器中双击运行它,直到看见“完成”!
5、检查所有文件是否已自动重命名。
注意:如果有两个以上的文档依据其内容提取出来的文字相同,则会自动在文件名后面附加“_1”、“_2”、“_3”……。
需要修改名字的文档全部选中zd,右键-重命名,输入你需要的名字。比如输入日期2010-11-11,确定,文档名称就会出现变成2010-11-11(1),2010-11-11(2),2010-11-11(3),。。。。。。
希望对你有帮助哦~

参考文献:http://zhidao.baidu.com/question/196937506.html

可以用脚本来做。

1、用记事本新建一个文本文件,把它保存为“批量重命名.vbs”(注意不要弄成了“批量重命名.vbs.txt”,也就是要确保其扩展名为“.vbs”);

2、把下列代码粘贴到这个VBS文件中:
Option Explicit

Const g_strRootPath = "c:\Temp\docs\Word\ToRename\" ' 指定存放所有e799bee5baa6e997aee7ad94e78988e69d83362文件的目录,可以有子目录
Const g_nTitleMaxLen = 16 ' 指定获取文档里面第一段中的前多少个字符来作为文件名

Call Main

' 主函数入口
Sub Main()

Dim fso, oFolder, oWordApp

Set oWordApp = CreateObject("Word.Application")
Set fso = CreateObject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder(g_strRootPath)

RenameDocFilesUnderFolder oWordApp, fso, oFolder

oWordApp.Quit
Set oWordApp = Nothing

MsgBox "完成!"

End Sub

' 重命名指定文件夹(递归)下面的所有Word文件,按照文件里面的第一句可见的文字命名
Sub RenameDocFilesUnderFolder(oWordApp, fso, oFolder)

Dim oSubFolder, oFile, oDoc
Dim strTitle, strFileName

For Each oSubFolder In oFolder.SubFolders
RenameDocFilesUnderFolder oWordApp, fso, oSubFolder
Next

For Each oFile In oFolder.Files
Set oDoc = oWordApp.Documents.Open(oFile.Path)
strTitle = GetFirstVisibleTextContent(oDoc)
oDoc.Close
Set oDoc = Nothing

If Len(strTitle) <> 0 Then
strFileName = fso.BuildPath(fso.GetParentFolderName(oFile.Path), strTitle & "." & fso.GetExtensionName(oFile.Path))
strFileName = GetUniqueFileName(fso, strFileName)
fso.MoveFile oFile.Path, strFileName
End If
Next

End Sub

' 获取指定文档第一行可见文字
Function GetFirstVisibleTextContent(oDoc)

Dim oParagraph
Dim strContent

For Each oParagraph In oDoc.Paragraphs
strContent = GetSafeFileName(oParagraph.Range.Text)
If Len(strContent) <> 0 Then
GetFirstVisibleTextContent = strContent
Exit Function
End If
Next

GetFirstVisibleTextContent = ""

End Function

' 过滤文件名里面的无效字符
Function GetSafeFileName(strFileName)

Dim arrUnsafeCharacters, strUnsafeChar
Dim nIndex

arrUnsafeCharacters = Array("\", "/", ":", "*", "?", """", "<", ">", "|")

For nIndex = 0 To &H2F
strFileName = Replace(strFileName, Chr(nIndex), "")
Next

For Each strUnsafeChar In arrUnsafeCharacters
strFileName = Replace(strFileName, strUnsafeChar, "")
Next

GetSafeFileName = Left(Trim(strFileName), g_nTitleMaxLen)

End Function

' 获取不重复的文件名,如果有重名则在文件名后面附加“_1”、“_2”……
Function GetUniqueFileName(fso, strFullName)

Dim strParentFolder, strBaseName, strExtensionName
Dim nIndex

If Not fso.FileExists(strFullName) Then
GetUniqueFileName = strFullName
Exit Function
End If

strParentFolder = fso.GetParentFolderName(strFullName)
strBaseName = fso.GetBaseName(strFullName)
strExtensionName = fso.GetExtensionName(strFullName)

nIndex = 0

While fso.FileExists(strFullName)
nIndex = nIndex + 1
strFullName = fso.BuildPath(strParentFolder, strBaseName & "_" & nIndex & "." & strExtensionName)
Wend

GetUniqueFileName = strFullName

End Function

3、修改代码中开始部分的两个设置,即:存放等待重命名的Word文件的根目录,以及获取文档第一段内容时最多保留多少个字符。

4、保存这个VBS文件,在资源管理器中双击运行它,直到看见“完成”!

5、检查所有文件是否已自动重命名。

注意:如果有两个以上的文档依据其内容提取出来的文字相同,则会自动在文件名后面附加“_1”、“_2”、“_3”……。

如果有什么问题,请和我联系。

相关阅读

关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网