如何使用宏在MS Word中添加表格标题?

时间:2016-12-16 12:05:12

标签: vba vbscript ms-word macros captions

亲爱的所有我试图将字幕修改为MS Word中的100个现有现有表,并避免这个繁琐的过程,我希望使用内置的VB宏功能。

例如,如果我的表位于以下部分的文档内容中:

  1. 简介
    1.1目标
  2. 我希望用“简介 - 目标”修改表格标题。因此,如果表格标题已经是“表1-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