|
jiminyanyan 发表于 2014-5-19 21:47
赵老师,我想把文件夹及子文件夹中的word 的内容由 蓝天 改为白云,怎么不成功呢。。。。 - Private Sub 确定_Click()
- On Error Resume Next
- Dim Fso As Object, Folder As Object, arrf$(), mf&
- Dim str1 As String
- Dim str2 As String
- Set Fso = CreateObject("Scripting.FileSystemObject")
- str1 = 新名称.Text
- str2 = 替换名称.Text
- 'Set Folder = Fso.GetFolder(路径)
- 'Call GetFiles(Folder, str1, str2)
- Set Folder = Fso.GetFolder(路径)
- Call 替换(Folder, arrf, mf)
- With CreateObject("Word.Application")
- .Visible = False
- For i = 1 To mf
- .Documents.Open arrf(i)
- .Selection.HomeKey Unit:=6
- Do While .Selection.Find.Execute(str1)
- .Selection.Text = str2 '替换字符串
- .Selection.HomeKey Unit:=6
- Loop
- .Documents.Close True
- Next
- .Quit
- End With
- MsgBox "更改完毕!"
- Set Folder = Nothing
- Set Fso = Nothing
-
- End Sub
复制代码- Sub 替换(ByVal Folder As Object, arr$(), m&)
- Dim SubFolder As Object
- Dim file As Object
- For Each file In Folder.Files
- If file.Name Like "*.doc" Then
- m = m + 1
- ReDim Preserve arr(1 To m)
- arr(m) = file
- End If
- Next
- For Each SubFolder In Folder.SubFolders
- Call 替换(SubFolder, arr, m)
- Next
- Set SubFolder = Nothing
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|