主题:文档批量查找/替换程序如何编写?
文档批量查找/替换程序如何编写?如Word、CAD文档等等,要把好多个位于不同目录下面的WORD、EXCEL、Powerpoint、CAD、TXT等文档里的敏感字眼(包括标题)替换掉,如“美国”换成“某国” ... ,写了如下代码:
'--替换目录
Sub ReplaceDir(dir As String)
Dim fso As New FileSystemObject, fo as Folder, fo1 as Folder, f as File
Set fo = fso.GetFolder(dir) '--初始目录
For Each f In fo.Files
If UCase(Right(f.Name, 4)) = ".DOC" And Left(f.Name, 1) <> "~" Then
ReplaceFile (f.Path)
End If
Next
For Each fo1 In fo.SubFolders
ReplaceDir (fo1.Path)
Next
End Sub
'--替换文件
Sub ReplaceFile(fileName As String)
Dim doc As Object
On Error Resume Next
Set doc = GetObject(fileName)
doc.Visible = False
For i = 0 To UBound(aText)
doc.ActiveWindow.Selection.Find.Execute "要替换的词", False, False, False, False, False, &_True, 1, False, "被替换的词", 2, False, True, False, False'稍微修改一下,可以实现多个词语的替换
Next doc.Save
doc.Close
Set doc = Nothing
End Sub
请问如何修改,把这个程序生成可执行文件?最好可实现多个词语的替换?如何包括CAD等格式文件呢?
'--替换目录
Sub ReplaceDir(dir As String)
Dim fso As New FileSystemObject, fo as Folder, fo1 as Folder, f as File
Set fo = fso.GetFolder(dir) '--初始目录
For Each f In fo.Files
If UCase(Right(f.Name, 4)) = ".DOC" And Left(f.Name, 1) <> "~" Then
ReplaceFile (f.Path)
End If
Next
For Each fo1 In fo.SubFolders
ReplaceDir (fo1.Path)
Next
End Sub
'--替换文件
Sub ReplaceFile(fileName As String)
Dim doc As Object
On Error Resume Next
Set doc = GetObject(fileName)
doc.Visible = False
For i = 0 To UBound(aText)
doc.ActiveWindow.Selection.Find.Execute "要替换的词", False, False, False, False, False, &_True, 1, False, "被替换的词", 2, False, True, False, False'稍微修改一下,可以实现多个词语的替换
Next doc.Save
doc.Close
Set doc = Nothing
End Sub
请问如何修改,把这个程序生成可执行文件?最好可实现多个词语的替换?如何包括CAD等格式文件呢?