语法高亮可使用VBA中的查找替换功能,如对于Delphi可先查找到关键字,然后将其设为蓝色即可,具体代码为:
1 Sub Replace1()
2
3 Dim i As Integer
4
5 Dim arr(15) as String
6
7 arr(0)="type" :arr(1)="class" : arr(2) ="unit" : arr(3)="begin" : arr(4)="end" : arr(5)="if" : arr(6)="else"
8
9 arr(7)="const" :arr(8)="var" : arr(9) ="procedure" : arr(10)="function" : arr(11)="then" : arr(12)="nil" : arr(13)="to" : arr(14)="while"
10
11 for i=LBound(arr) to UBound(arr)
12
13 Selection.Find.ClearFormatting
14
15 Selection.Find.Replacement.ClearFormatting
16
17 with Selection.Find
18
19 .Text=arr(i)
20 .Replacement.Font.Color=wdColorBlue
21 .Replacement.Text=arr(i)
22 .Forword=True
23 .Wrap=wdFindContinue
24 .Format=True
25 .MatchCase=False
26 .MatchByte=True
27 .MatchWildCards=False
28 .MatchSoundsLike=False
29 .MatchAllWordForms=False
30
31 End With
32 Selections.Find.Execute Replace:=wdReplaceAll
33
34 nexit i
35
36 End Sub
也可以先复制到NotePad++中,再打开菜单NppExport->Copy HTML to ClipBoard,再打开word并粘贴即可
具体步骤见http://blog.163.com/rongting_chen/blog/static/16490684420113247107144/