整理文档比较费事,提供个脚本放在VBA里,使Word 代码高亮的一种方法是改变颜色

 'script to high light code In document

Private Function isKeyword(w) As Boolean

    Dim keys As New Collection

    With keys

.Add "onStart": .Add "Log": .Add "volatile": .Add "friend"
.Add "abstract": .Add "long": .Add "while": .Add "if"
.Add "Activity": .Add "native": .Add "FALSE": .Add "implements"
.Add "asm": .Add "new": .Add "import"
.Add "auto": .Add "new?": .Add "enabled": .Add "inlIne"
.Add "bool": .Add "android": .Add "instanceof"
.Add "boolean": .Add "onBind": .Add "receiver": .Add "int"
.Add "boolean?": .Add "onCreate": .Add "exported": .Add "int?"
.Add "break": .Add "onDestroy": .Add "filter": .Add "Intent"
.Add "BroadcastReceiver": .Add "onRebind": .Add "action": .Add "interface"
.Add "byte": .Add "onUnbind": .Add "category": .Add "isDebug?"
.Add "case": .Add "package": .Add "application": .Add "synchronized"
.Add "char": .Add "private": .Add "manifest": .Add "template"
.Add "class": .Add "protected": .Add "xmlns": .Add "this"
.Add "class?": .Add "protected?": .Add "version": .Add "throw?"
.Add "const": .Add "public": .Add "encoding": .Add "transient"
.Add "ContentProvider": .Add "register": .Add "utf": .Add "typename"
.Add "continue": .Add "return": .Add "INTERNET": .Add "union"
.Add "default": .Add "sendOrderBroadcast": .Add "RECEIVE_USER_PRESENT": .Add "unsigned"
.Add "do": .Add "Service": .Add "WAKE_LOCK": .Add "virtual"
.Add "double": .Add "short": .Add "READ_PHONE_STATE": .Add "void"
.Add "else": .Add "signed": .Add "WRITE_EXTERNAL_STORAGE"
.Add "enum": .Add "static": .Add "READ_EXTERNAL_STORAGE"
.Add "explicit": .Add "static?": .Add "VIBRATE": .Add "CHANGE_WIFI_STATE"
.Add "extends": .Add "strictfp": .Add "WRITE_SETTINGS": .Add "CHANGE_NETWORK_STATE"
.Add "extern": .Add "String?": .Add "ACCESS_NETWORK_STATE": .Add "@"
.Add "final": .Add "struct": .Add "ACCESS_WIFI_STATE": .Add "super"
.Add "float": .Add "for": .Add "switch": .Add "typedef": .Add "sizeof"
.Add "try": .Add "namespace": .Add "catch": .Add "operator"
.Add "cast": .Add "NULL": .Add "null": .Add "delete": .Add "throw"
.Add "dynamic": .Add "reinterpret": .Add "true": .Add "TRUE"
.Add "pub": .Add "provider": .Add "authorities": .Add "Add": .Add "get": .Add "set"
.Add "uses": .Add "permission": .Add "allowBackup"
.Add "grant": .Add "URI": .Add "meta": .Add "data": .Add "false": .Add "string": .Add "integer"
End With isKeyword = isSpecial(w, keys) End Function Private Function isSpecial(ByVal w As String, ByRef col As Collection) As Boolean For Each i In col If w = i Then isSpecial = True Exit Function End If Next isspeical = False End Function Private Function isOperator(w) As Boolean Dim ops As New Collection With ops .Add "+": .Add "-": .Add "*": .Add "/": .Add "&": .Add "^": .Add ";" .Add "%": .Add "#": .Add "!": .Add ":": .Add ",": .Add "." .Add "||": .Add "&&": .Add "|": .Add "=": .Add "++": .Add "--" .Add "'": .Add """" End With isOperator = isSpecial(w, ops) End Function ' set the style of selection Private Function isType(ByVal w As String) As Boolean Dim types As New Collection With types .Add "void": .Add "struct": .Add "union": .Add "enum": .Add "char": .Add "short": .Add "int" .Add "long": .Add "double": .Add "float": .Add "signed": .Add "unsigned": .Add "const": .Add "static" .Add "extern": .Add "auto": .Add "register": .Add "volatile": .Add "bool": .Add "class": .Add " private" .Add "protected": .Add "public": .Add "friend": .Add "inlIne": .Add "template": .Add "virtual" .Add "asm": .Add "explicit": .Add "typename" End With isType = isSpecial(w, types) End Function Sub SyntaxHighlight() Dim wordCount As Integer Dim d As Integer ' set the style of selection Selection.Style = "java code" d = wordCount = Selection.Words.Count Selection.StartOf wdWord While d < wordCount d = d + Selection.MoveRight(wdWord, , wdExtend) w = Selection.Text If isKeyword(Trim(w)) = True Then Selection.Font.Color = wdColorBlue ElseIf isType(Trim(w)) = True Then Selection.Font.Color = wdColorDarkRed ' 深绿色。lIne comment 水绿色 wdColorAutomatic wdColorBlueGray Selection.Font.Bold = True ElseIf isOperator(Trim(w)) = True Then Selection.Font.Color = wdColorBrown ' 鲜绿色。 ElseIf Trim(w) = "//" Then 'lIne comment Selection.MoveEnd wdLine, commentWords = Selection.Words.Count d = d + commentWords Selection.Font.Color = wdColorGreen ' 灰色底纹。 Selection.MoveStart wdWord, commentWords ElseIf Trim(w) = "/*" Then 'block comment While Selection.Characters.Last <> "/" Selection.MoveLeft wdCharacter, , wdExtend Selection.MoveEndUntil ("*") Selection.MoveRight wdCharacter, , 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

Word 代码高亮的更多相关文章

  1. Word中使用代码高亮插件

    Word中使用代码高亮插件 1.下载并安装:SyntaxHighlighter4Word.zip 解压,然后双击bin\word2010\Kong.SyntaxHighlighter.Word2010 ...

  2. 如何在博客中使用SublimeText风格的代码高亮样式

    因为觉得博客园自带的代码高亮样式很单一,不符合作为前端的我的审美习惯,于是下定决心要想办法折腾出一个方法来应用上另外一套代码高亮样式. 虽然探索的过程是很痛苦的,但最后还是成功了,但也不枉付出的那些努 ...

  3. 20141127 测试使用Word2013书写博客(代码高亮+公式支持)。

      PS :又经过几次测试,发现用于Word2010的高亮插件在Word2013上排版效果不是很好,慎用.不过公式编辑倒是挺方便的 测试使用Word2013书写博客. 大概一个月前,使用WindowL ...

  4. 如何使用SublimeText风格的代码高亮样式 添加Zed Coding(EMMET)插件

    因为觉得博客园自带的代码高亮样式很单一,不符合作为前端的我的审美习惯,于是下定决心要想办法折腾出一个方法来应用上另外一套代码高亮样式. 虽然探索的过程是很痛苦的,但最后还是成功了,但也不枉付出的那些努 ...

  5. 使用word2016发有代码高亮的博客

    复制使用notepad++,eclipse这类有高亮的编辑器编写的代码到word中是默认有高亮的. 测试有没有代码高亮(eclipse代码): package p_day1; public class ...

  6. 如何在Open Live Writer(OLW)中使用precode代码高亮Syntax Highlighter

    早先Microsotf的Windows Live Writer(WLW)现在已经开源了,并且更名为Open Live Writer,但是现在Windows Live Writer还是可以现在,Open ...

  7. highlight.js 代码高亮插件

    官网:https://highlightjs.org/ API:http://highlightjs.readthedocs.org/en/latest/api.html 1. 简单使用: <l ...

  8. 7个高性能JavaScript代码高亮插件

    本文由码农网 – 小峰原创,转载请看清文末的转载要求,欢迎参与我们的付费投稿计划! 对于喜欢写技术博客的同学来说,一定对代码高亮组件非常熟悉.一款优秀的JavaScript代码高亮插件,将会帮助你渲染 ...

  9. 如何在 Evernote 中支持代码高亮

    Evernote 本身不支持代码高亮,在 Apple App-Store 上有一个建立在 Evernote 上的 EverCode,可以支持代码高亮,需要付费.虽然只有¥5,但是这个 App 似乎只能 ...

随机推荐

  1. 【BZOJ 3470】3470: Freda’s Walk 期望

    3470: Freda’s Walk Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 42  Solved: 22 Description 雨后的Poet ...

  2. android studio 汉化 个性化 美化 快速操作项目 目录

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha 汉化包 百度云盘 下载地址:https://pan.baidu.com/s/1pLjwy ...

  3. 鸟哥的私房菜:Bash shell(三)-命令别名与历史指令

    一  命令别名设定: alias, unalias 命令别名是一个很有趣的东西,特别是你的惯用指令特别长的时候!还有, 增设预设的属性在一些惯用的指令上面,可以预防一些不小心误杀档案的情况发生的时候! ...

  4. bzoj 3306

    以1号节点为根,弄出DFS序,我们发现,对于一个询问:(rt,u),以rt为根,u节点的子树中的最小点权,我们可以根据rt,u,1这三个节点在同一条路径上的相对关系来把它转化为以1为根的在DFS序上的 ...

  5. UVA 11945 Financial Management 水题

    Financial Management Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 acm.hust.edu.cn/vjudge/problem/vis ...

  6. BZOJ 1008 [HNOI2008]越狱 排列组合

    1008: [HNOI2008]越狱 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 4788  Solved: 2060[Submit][Status] ...

  7. PAT甲级1123. Is It a Complete AVL Tree

    PAT甲级1123. Is It a Complete AVL Tree 题意: 在AVL树中,任何节点的两个子树的高度最多有一个;如果在任何时候它们不同于一个,则重新平衡来恢复此属性.图1-4说明了 ...

  8. 数据表-java类的映射

    1.一个数据表对应一个java类 2.数据表的字段对应java类的属性 3.一对多的数据表关系 一方用一个java对象表示 多方用一个java对象数组表示 4.多对多的数据表关系:采用中间表,将多对多 ...

  9. (转)js中的hasOwnProperty和isPrototypeOf方法

    hasOwnProperty:是用来判断一个对象是否有你给出名称的属性或对象.不过需要注意的是,此方法无法检查该对象的原型链中是否具有该属性,该属性必须是对象本身的一个成员.isPrototypeOf ...

  10. Cocos2d-x移植android增加震动效果

    cpp部分通过jni调用java静态函数 头文件: #include <jni.h> #include "cocos2d.h" #include "platf ...