Bootstrap

【vba-4】vba操作word新增表格题注

Sub addTz()
    Word.Application.ScreenUpdating = False
    Dim oRng As Range
    Dim oDoc As Document
    Dim oCL As CaptionLabel
    Dim oT As Table
    Set oDoc = Word.ActiveDocument
    With oDoc
        Set oCL = Word.CaptionLabels.Add("表")
        '设置新增的题注样式
        With oCL
            .ChapterStyleLevel = 1
            .IncludeChapterNumber = True
            .NumberStyle = wdCaptionNumberStyleArabic
        End With
        i = 1
        For Each oT In .Tables
            Set oRng = .Range(oT.Range.Start - 2, oT.Range.Start - 1)
                With oRng
                    '将oRng对象按照整个段落选中,oRng对象自动变为整个段落的Range对象
                    oRng.Expand wdParagraph
                    '如果有自动编号 删除
                    oRng.ListFormat.RemoveNumbers
                    '读取标题的文本内容
                    sText = VBA.Replace(oRng.Text, Chr(13), "")
                    .Delete
         
;