1、启动Word文档软件。
2、按Ctrl+O打开需要修改的文件。
3、打开需要修改的文件后,在word菜单栏点击“替换”按钮。
4、在d出的替换对话穗笑框中:首仿族悄选查找到需要替换的内容,再输入替备渣换为的内容。
5、然后点击“全部替换”即可,如图所示:
不会改变。根据word官网资料显示,在word中当一个文件被更名后文件的内容不会改变。
Word文档,它是电子文悄者档的一种格式(桥运梁后缀名为docx),打开这种格式文档的软件就叫Word,其主要功能是用户使用电脑通过该软件,可以撰写、敏运编辑一些文档。
Sub ChangeDocName(sPath As String)Dim wdApp
Dim oDoc
Dim sFileName As String
Dim sNewName As String
Dim i As Integer
On Error Resume Next
Set wdApp = CreateObject("Word.Application")
On Error GoTo 0
If wdApp Is Nothing Then
MsgBox "创建word实例失败,程序将退出。本程序只能在装有word程序的电脑局基运上运行。"
Exit Sub
End If
If Right(sPath, 1) <>"\" Then sPath = sPath &"\"
sFileName = Dir(sPath &"*.doc", vbHidden + vbSystem)
Do While sFileName <>锋谈 ""
i = 0
Set oDoc = wdApp.Documents.Open(sapth &sFileName)
oDoc.Select
wdApp.Selection.HomeKey Unit:=wdStory
wdApp.Selection.Expand wdLine
sNewName = wdApp.Selection.Text
sNewName = Replace(sNewName, "\", "")
sNewName = Replace(sNewName, "/", "")
sNewName = Replace(sNewName, ":", "")
sNewName = Replace(sNewName, "?", "")
sNewName = Replace(sNewName, "*", "")
sNewName = Replace(sNewName, ">", "")
sNewName = Replace(sNewName, "<", "")
sNewName = Replace(sNewName, """", "")
oDoc.Close
Err.Clear
On Error GoTo FileAlreadyExist
Name sPath &sFileName As sPath &sNewName &".doc"
FileAlreadyExist:
If Err.Number >0 Then
i = i + 1
Name sPath &sFileName As sPath &sNewName &i &".doc"
End If
On Error GoTo 0
sFileName = Dir()
Loop
Set wdApp = Nothing
End Sub
上述代码中已经加入了常见错误的处理,使用的时候将文件夹的完整路径作为参桐梁数输入就可以了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)