Word中怎么设置代码高亮 word中关键字高亮的设置方法( 二 )


Selection.MoveEndUntil (*)
Selection.MoveRight wdCharacter,2,wdExtend
Wend
commentWords = Selection.Words.Count
d = d + commentWords
Selection.Font.Color = wdColorGreen
Selection.MoveStart wdWord,commentWords
End If
' move the start of selection to next word
Selection.MoveStart wdWord
Wend
' prepare For set lIne number
Selection.MoveLeft wdWord,wordCount,wdExtend
SetLIneNumber
End Sub
Private Sub SetLIneNumber()
Dim lines As Integer
lines = Selection.Paragraphs.Count
Selection.StartOf wdParagraph
For l = 1 To lines
lIneNum = l
If l10 Then
lIneNum = lIneNum
End If
Selection.Text = lIneNum
Selection.Font.Bold = False
Selection.Font.Color = wdColorAutomatic
p = Selection.MoveDown(wdLine,1,wdMove)
Selection.StartOf wdLine
Next
End Sub
6、 选定代码文本,然后执行highlight脚本: 视图-宏- 选中SyntaxHighlight-运行,然后执行就可以了 。处理较长代码时需要一定时间,请耐心等待 。
注意事项: 处理前一定要对原文章进行备份,以免前功尽弃 。处理较长代码时需要一定时间,请耐心等待 。

经验总结扩展阅读