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 似乎只能 ...
随机推荐
- bzoj hash+map+set
先对原串分组hash,查询就是看某一区间内是否出现某值. 可以每个值存一个集合,保存这个值出现的位置.(也可以建可持久化值域线段树) map<int,set<int> >很省事 ...
- spring---aop(8)---Spring AOP中optimize
写在前面 optimize是ProxyConfig的属性.意思为 是否对生产代理策略使用优化. public class ProxyConfig implements Serializable { p ...
- Perforce-Server迁移
Author: JinDate: 20140827System: Windows 2008 R2 从Windows 2008 R2迁移到Windows 2008 R2 linux版本迁移官方文档htt ...
- UVALive 3135--Argus+自己定义优先队列的优先规则
题目链接:id=18684">点击进入 仅仅是题意比較难懂,读懂题后全然能够用优先队列水过去.这次学会自己定义优先队列的优先规则,事实上就是在结构体中重载一下<运算符. 代码例如 ...
- Delphi7下使用FastMM4
1> 将文件Replacement BorlndMM DLL/Precompiled/for Delphi IDE/Performance/BorlndMM.dll,替换掉Delphi/Bin下 ...
- golang 字符串与整数, 布尔转换 strconv
strconv 是golang对于字符串和基本数据类型之间的转换字符串转整数testStr := "1000" testInt, err := strconv.Atoi(testS ...
- 如何在IE11中开启WebGL暨微软和WebGL的恩怨情仇录
正如我们上周报道的,国外开发者Francois Remy在泄露版Windows Blue附带的Internet Explorer 11中发现,WebGL接口已经封装完成,但功能上还未能开放支持.在这之 ...
- spring mvc实现restful
restful它的核心是将所有的 Api 都理解为一个网络资源.把api映射成资源 restful它的核心是将所有的 Api 都理解为一个网络资源.把api映射成资源 把api映射成资源,把api映射 ...
- XFire Web Service
Web Service 创建HelloWorldService项目 首先要启动Web Service Project 向导.该向导由三个页面组成,第一页设置Web项目配置的详细信息:第二页设置XFir ...
- 【java】关于Map的排序性的一次使用,有序的Map
关于Map的排序性的一次使用,有序的Map >>>>> hashmap是按key的hash码排序的,而treemap是利用comparator 进行key的自然排序的 / ...