亲爱的所有我试图将字幕修改为MS Word中的100个现有现有表,并避免这个繁琐的过程,我希望使用内置的VB宏功能。
例如,如果我的表位于以下部分的文档内容中:
我希望用“简介 - 目标”修改表格标题。因此,如果表格标题已经是“表1-1”,我希望它为:
表1-1简介目标
宏运行后,这可能吗?怎么样?
谢谢!
答案 0 :(得分:0)
下面的脚本是一个批处理过程,它对文件夹中的所有Word文件执行查找/替换例程。
Sub FindReplaceAll()
Dim MyDialog As FileDialog, GetStr(1 To 100) As String
'100 files is the maximum applying this code
On Error Resume Next
Set MyDialog = Application.FileDialog(msoFileDialogFilePicker)
With MyDialog
.Filters.Clear
.AllowMultiSelect = True
i = 1
If .Show = -1 Then
For Each stiSelectedItem In .SelectedItems
GetStr(i) = stiSelectedItem
i = i + 1
Next
i = i - 1
End If
Application.ScreenUpdating = False
For j = 1 To i Step 1
Set Doc = Documents.Open(FileName:=GetStr(j), Visible:=True)
Windows(GetStr(j)).Activate
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "Marriott International" 'Find What
.Replacement.Text = "Marriott" 'Replace With
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Application.Run macroname:="NEWMACROS"
ActiveDocument.Save
ActiveWindow.Close
Next
Application.ScreenUpdating = True
End With
MsgBox "operation end, please view", vbInformation
End Sub
'这个想法来自这里。
' https://www.extendoffice.com/documents/word/1002-word-replace-multiple-files.html