写宏,把加粗并且字数小于20的段落的样式与格式设置为二级标题。 参考Sub c() ' '标题 9 是以(1)等开头的数字 Dim I As Paragraph, oTxT As String, mySTr As String, mySTyLE As Inte
写宏,把加粗并且字数小于20的段落的样式与格式设置为二级标题。 参考Sub c() ' '标题 9 是以(1)等开头的数字 Dim I As Paragraph, oTxT As String, mySTr As String, mySTyLE As Integer, n As Integer For Each I In ActiveDocument.Paragraphs If I.Range.Information(wdWithInTable) = False Then oTxT = I.Range.Text If oTxT Like "第?章*" Or oTxT Like "第??章*" Or oTxT Like "第???章*" Then I.Style = wdStyleHeading1 GoTo NT End If mySTr = "" For n = 1 To VBA.Len(oTxT) If Mid(oTxT, n, 1) Like "[0-9.]" Then mySTr = mySTr & Mid(oTxT, n, 1) Else Exit For Next If VBA.Len(mySTr) > 0 Then mySTyLE = UBound(VBA.Split(mySTr, ".")) Select Case mySTyLE Case 3 '以 的形式开头的段落 I.Style = wdStyleHeading4 Case 2 '以 1.1.1 的形式开头的段落 I.Style = wdStyleHeading3 Case 1 '以 1.1 的形式开头的段落 I.Style = wdStyleHeading2 Case Else '其他值时 I.Style = wdStyleNormal End Select Else I.Style = wdStyleNormal '其它为正文样式 End If End If NT: Next End Sub
展开
全部