Word 代码高亮
整理文档比较费事,提供个脚本放在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 代码高亮的更多相关文章
- Word中使用代码高亮插件
Word中使用代码高亮插件 1.下载并安装:SyntaxHighlighter4Word.zip 解压,然后双击bin\word2010\Kong.SyntaxHighlighter.Word2010 ...
- 如何在博客中使用SublimeText风格的代码高亮样式
因为觉得博客园自带的代码高亮样式很单一,不符合作为前端的我的审美习惯,于是下定决心要想办法折腾出一个方法来应用上另外一套代码高亮样式. 虽然探索的过程是很痛苦的,但最后还是成功了,但也不枉付出的那些努 ...
- 20141127 测试使用Word2013书写博客(代码高亮+公式支持)。
PS :又经过几次测试,发现用于Word2010的高亮插件在Word2013上排版效果不是很好,慎用.不过公式编辑倒是挺方便的 测试使用Word2013书写博客. 大概一个月前,使用WindowL ...
- 如何使用SublimeText风格的代码高亮样式 添加Zed Coding(EMMET)插件
因为觉得博客园自带的代码高亮样式很单一,不符合作为前端的我的审美习惯,于是下定决心要想办法折腾出一个方法来应用上另外一套代码高亮样式. 虽然探索的过程是很痛苦的,但最后还是成功了,但也不枉付出的那些努 ...
- 使用word2016发有代码高亮的博客
复制使用notepad++,eclipse这类有高亮的编辑器编写的代码到word中是默认有高亮的. 测试有没有代码高亮(eclipse代码): package p_day1; public class ...
- 如何在Open Live Writer(OLW)中使用precode代码高亮Syntax Highlighter
早先Microsotf的Windows Live Writer(WLW)现在已经开源了,并且更名为Open Live Writer,但是现在Windows Live Writer还是可以现在,Open ...
- highlight.js 代码高亮插件
官网:https://highlightjs.org/ API:http://highlightjs.readthedocs.org/en/latest/api.html 1. 简单使用: <l ...
- 7个高性能JavaScript代码高亮插件
本文由码农网 – 小峰原创,转载请看清文末的转载要求,欢迎参与我们的付费投稿计划! 对于喜欢写技术博客的同学来说,一定对代码高亮组件非常熟悉.一款优秀的JavaScript代码高亮插件,将会帮助你渲染 ...
- 如何在 Evernote 中支持代码高亮
Evernote 本身不支持代码高亮,在 Apple App-Store 上有一个建立在 Evernote 上的 EverCode,可以支持代码高亮,需要付费.虽然只有¥5,但是这个 App 似乎只能 ...
随机推荐
- JavaSE基础之矩阵运算
JavaSE基础之矩阵运算 1.矩阵类:Matrix.java 包括矩阵的加.乘运算,行列式的求解,最大最小元素等 package cn.com.zfc.help; import java.text. ...
- BlocksKit(2)-DynamicDelegate
BlocksKit(2)-DynamicDelegate 动态代理可以说是这个Block里面最精彩的一部分了,可以通过自己给一个类的的协议方法指定对应的block来实现让这个协议的回调都直接在bloc ...
- java编译优化
#java编译器对`String常量表达式`的优化: - 1.String+String 可以被编译器识别为常量表达 String a="ab" ; String b=" ...
- php curl伪造referer
CURL方式: SOCKET方式: file_get_contents方法: 通过上面的代码,我们就把referer地址伪装为http://www.xxxx.com,你可以写一段代码: $_SERVE ...
- Android Path Time ScrollBar(Path 时间轴)
版本号:1.0 日期:2014.4.22 版权:© 2014 kince 转载注明出处 这是仿Path2.0UI的一个demo的截图,我最早是在农民伯伯的这篇博客中看到的[Andorid X 项目 ...
- startActivities的使用
和startActivity()类似,startActivities也是界面跳转,可是传入的intent是一个数组,也就是说是多个. 如果我传入的是两个intent: I1和I2.则调用startAc ...
- 使用Bootstrap 3开发响应式网站实践01,前期准备、导航区域等
"使用Bootstrap 3开发响应式网站实践"系列,将使用Bootstrap 3.2制作一个自适应网站,无论是在电脑.平板,还是手机上,都呈现比较好的效果.在电脑浏览器上的最终效 ...
- 使用 MVC 5 的 EF6 Code First 入门 系列:建立一个EF数据模型
这是微软官方SignalR 2.0教程Getting Started with Entity Framework 6 Code First using MVC 5 系列的翻译,这里是第一篇:建立一个E ...
- 结合MapReduce和数据集Combining datasets with MapReduce
While in the SQL-world is very easy combining two or more datasets - we just need to use the JOIN ke ...
- Coursera课程《大家的python》(Python for everyone)课件
You can access the Google Drive containing all of the current and in-progress lecture slides for thi ...