|
楼主 |
发表于 2017-10-24 14:27
|
显示全部楼层
本帖最后由 chenwenming 于 2017-10-27 06:49 编辑
为什么这代码只设标题的前半部分,后半部分不设置呢?求指点
Sub AAA()
Dim MyStr As String, YouStr As String
Dim apar As Paragraph
MyStr = "第"
YouStr = "一二三四五六七八九十"
With ActiveDocument
For Each apar In .Paragraphs
If apar.Range.Information(wdWithInTable) = False Then
With apar.Range
If .Find.Execute(findtext:="第[一二三四五六七八九十]{1,}章 ", Forward:=True, MatchWildcards:=True) = True And InStr(MyStr, ActiveDocument.Range(apar.Range.Start, apar.Range.Start + 1).Text) > 0 Then
.Font.Name = "仿宋" '字体
.Font.Bold = True '加粗
.Font.Size = 16 '字号,14=四号;16=三号……
.ParagraphFormat.Alignment = wdAlignParagraphCenter '居中对齐
.ParagraphFormat.OutlineLevel = wdOutlineLevel1 '设为标题1
'i.Range.Style = wdStyleHeading3
ElseIf .Find.Execute(findtext:="第[一二三四五六七八九十]{1,}节 ", Forward:=True, MatchWildcards:=True) = True And InStr(MyStr, ActiveDocument.Range(apar.Range.Start, apar.Range.Start + 1).Text) > 0 Then
.Font.Name = "等线(中文正文)" '字体
.Font.Bold = True '加粗
.Font.Size = 16 '字号,14=四号;16=三号……
.ParagraphFormat.Alignment = wdAlignParagraphCenter '居中对齐
.ParagraphFormat.OutlineLevel = wdOutlineLevel2 '设为标题1
ElseIf .Find.Execute(findtext:="[一二三四五六七八九十]{1,}、", Forward:=True, MatchWildcards:=True) = True And InStr(YouStr, ActiveDocument.Range(apar.Range.Start, apar.Range.Start + 1).Text) > 0 Then
.Font.Name = "等线(中文正文)" '字体
.Font.Bold = True '加粗
.Font.Size = 10.5 '字号,14=四号;16=三号……
.ParagraphFormat.Alignment = wdAlignParagraphLeft '居中对齐
.ParagraphFormat.OutlineLevel = wdOutlineLevel3 '设为标题1
End If
End With
End If
Next
End With
End Sub
|
|