|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
问下各位大神,我想做成word中的’替换‘功能,但是一次比它多几个,想用textbox文本框控件来实现,如图1:
在网上找到代码,想这样改一下,如图2:怎么实现不了我的功能。
附代码:
Sub huan() '批量替换多个word文档中的内容
Application.ScreenUpdating = False
Dim MyPath As String, i As Integer, myDoc As Document
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "选择目标文件夹"
If .Show = -1 Then
MyPath = .SelectedItems(1)
Else
Exit Sub
End If
End With
With Application.FileSearch
.LookIn = MyPath
.FileType = msoFileTypeWordDocuments
If .Execute > 0 Then
For i = 1 To .FoundFiles.Count
Set myDoc = Documents.Open(FileName:=.FoundFiles(i), Visible:=False)
With myDoc.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Execute findtext:=TextBox1.Text, replacewith:=TextBox2.Text, MatchWildcards:=False, Replace:=wdReplaceAll
'.Execute findtext:="10kv", replacewith:="bbb", MatchWildcards:=False, Replace:=wdReplaceAll
End With
myDoc.Close True
Next
End If
End With
Application.ScreenUpdating = True
End Sub
|
-
图1
-
图2
|