整理文档比较费事,提供个脚本放在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. Django ORM训练专题

    图书信息系统 表结构设计 # 书 class Book(models.Model): title = models.CharField(max_length=32) publish_date = mo ...

  2. GITC简单感触

    GITC短暂的2天,去参加主要是想参与其中,了解其他家的技术,技术使用, 那些大牛,及大牛公司,大牛团队的一些事. 早上的主会场主要是介绍和宣传.半小时后就出去逛逛外面的分会场: 参与听了下 智能硬件 ...

  3. 持续集成之Jenkins插件使用(一)- 多个job之间的串并联

    转载自:http://qa.blog.163.com/blog/static/190147002201391661510655/ Jenkins除了开源和免费,还有一个最吸引人的功能之一就是支持插件. ...

  4. UVALive 5971

    Problem J Permutation Counting Dexter considers a permutation of first N natural numbers good if it ...

  5. Go语言Web框架gwk介绍 (一)

    今天看到Golang排名到前30名了,看来关注的人越来越多了,接下来几天详细介绍Golang一个web开发框架GWK. 现在博客园支持markdown格式发布文章么?后台的编辑器不太好用嘛. GWK ...

  6. 小程序在wxml页面中取整

    小程序无法像html中,在页面中直接parseInt() index.wxml {{price | Int}} 小程序还有另一种处理方法 wxs 是一种类似于js脚本的东西 filters.wxs v ...

  7. CentOS的update-grub2命令

    这个和Ubuntu还是有些区别,在CentOS修改成如下: grub2-mkconfig -o /boot/grub2/grub.cfg

  8. MVC文件上传04-使用客户端jQuery-File-Upload插件和服务端Backload组件实现多文件异步上传

    本篇使用客户端jQuery-File-Upload插件和服务端Badkload组件实现多文件异步上传.MVC文件上传相关兄弟篇: MVC文件上传01-使用jquery异步上传并客户端验证类型和大小  ...

  9. java内存溢出示例(堆溢出、栈溢出)

    堆溢出: /** * @author LXA * 堆溢出 */ public class Heap { public static void main(String[] args) { ArrayLi ...

  10. 【elasticsearceh】elasticsearch.yml配置文件详解

    主要内容如下: cluster.name: elasticsearch 配置es的集群名称,默认是elasticsearch,es会自动发现在同一网段下的es,如果在同一网段下有多个集群,就可以用这个 ...