解决了,在确定目录及页码不再改动以后,用以下VBA代码(如需改动,重新插入目录): '更改论文目录格式
Public Sub ChangCatalogueFormat()
Dim aField As Field Application.ScreenUpdating = False '循环查找目录域(Type值为wdFieldTOC)
For Each aField In ActiveDocument.Sections(1).Range.Fields
If aField.Type = wdFieldTOC Then
Exit For
End If
Next
aField.Select '选择该域
'去除目录链接,文档中用快捷键Ctrl+Shift+F9
Selection.Fields.Unlink
'去除字符的下划线,颜色设为自动
With Selection.Font
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.Color = wdColorAutomatic
End With
'替换制表符为"Times New Roman"五号
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^t"
.Replacement.Text = ""
With .Replacement.Font
'.NameFarEast = "宋体"
.NameAscii = "Times New Roman"
.NameOther = "Times New Roman"
.Name = "Times New Roman"
.Size = 10.5
.Bold = False '不加粗
.Italic = False '不是斜体
.Underline = wdUnderlineNone '没有下划线
.UnderlineColor = wdColorAutomatic '下划线颜色
.StrikeThrough = False '无着重号
.DoubleStrikeThrough = False '
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = False
.Color = wdColorAutomatic
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0
.Scaling = 100
.Position = 0
.Animation = wdAnimationNone
.EmphasisMark = wdEmphasisMarkNone
End With
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
'替换页码为五号宋体
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
With .Font
.Name = "宋体"
.Size = 14
End With
.Text = "^#"
.Replacement.Text = ""
With .Replacement.Font
.Name = "宋体"
.Size = 10.5
.Bold = False
End With
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With Application.ScreenUpdating = True
End Sub |