|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
老师好!
我这是班门弄斧啊。附上我的代码,请老师指教。
在这段代码中,大纲级别单独设置,与字体及其他段落参数没有关联。
Private Sub CommandButton1_Click()
Set OutlineLevelDic = CreateObject("Scripting.Dictionary") '设置大纲级别字典 后期引用
OutlineLevelDic.Add "正文", 10 '等同数值10
OutlineLevelDic.Add "1级", 1 '等同数值1
OutlineLevelDic.Add "2级", 2 '等同数值2
OutlineLevelDic.Add "3级", 3 '等同数值3
OutlineLevelDic.Add "4级", 4 '等同数值4
OutlineLevelDic.Add "5级", 5 '等同数值5
OutlineLevelDic.Add "6级", 6 '等同数值6
OutlineLevelDic.Add "7级", 7 '等同数值7
OutlineLevelDic.Add "8级", 8 '等同数值8
OutlineLevelDic.Add "9级", 9 '等同数值9
Box1 = OutlineLevelDic(ThisDocument.ComboBox1.Value) ' ThisDocument.ComboBox1.Value '读取段落级别设置参数
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "^13第[一二三四五六七八九十]章*^13" '查找内容可根据需要设置
.Replacement.Text = "^&"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchWildcards = True
i = 0
Do While .Execute '只能通过循环的方式修改大纲级别
With .Parent
j = ActiveDocument.Range(Start:=0, End:=.End).Characters.Count
If j < i Then Exit Do Else i = j
.MoveStart
With .Range.Font
.Name = "黑体" '字体型号
.Size = 15 '字体大小
.Color = wdColorRed
.Bold = True '是否加粗
End With
With .ParagraphFormat '对于段落格式,需要用此方式才能设置成功,如果像字体".Replacement.font"那样设置是无效的
.OutlineLevel = Box1
.Alignment = wdAlignParagraphCenter
.Space15 '1.5倍行距
'其他段落格式均可在此设置
End With
.Start = .End '因为Text的首尾为同一字符,还需对End调减1位(略)
End With
Loop
End With
End Sub
|
|