利用word的VBA,为代码统一表格宽度,底色及行号
如果文档中的代码表格时,感觉还是很快速有用的。
Sub HangHao()
'
' hanghao 宏
'
'
Dim parag As Paragraph
Dim nLineNum: nLineNum = 0
Dim selRge As Range
Set selRge = Selection.Range
For Each parag In Selection.Paragraphs
nLineNum = nLineNum + 1
bgNLineNum = nLineNum
selRge.Paragraphs(nLineNum).Range.InsertBefore (Format$(bgNLineNum, "00") & " ")
Next
' 背景色为morning的配色方案,RGB为(229,229,229)
With Selection.Tables(1)
With .Shading
.Texture = wdTextureNone
.ForegroundPatternColor = wdColorAutomatic
.BackgroundPatternColor = 15066597 '15066597这个数其实就是229*(2^16 + 2^8 + 1)
End With
Options.DefaultHighlightColorIndex = wdNoHighlight 'NeXT_Jobs新增的:清除“以不同颜色突出显示文本”,从而解决从VS中“保留源格式”复制带来的文本高亮问题
Selection.Range.HighlightColorIndex = wdNoHighlight 'NeXT_Jobs新增的:清除“以不同颜色突出显示文本”,从而解决从VS中“保留源格式”复制带来的文本高亮问题
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Borders(wdBorderTop).LineStyle = wdLineStyleNone
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
.Borders(wdBorderVertical).LineStyle = wdLineStyleNone
.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
.Borders.Shadow = False
End With
With Options
.DefaultBorderLineStyle = wdLineStyleSingle
.DefaultBorderLineWidth = wdLineWidth050pt
.DefaultBorderColor = wdColorAutomatic
End With
' 段落无首行缩进,行间距为固定值12磅
With Selection.ParagraphFormat
.LeftIndent = CentimetersToPoints(0)
.RightIndent = CentimetersToPoints(0)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceExactly '行距为“固定值”
.LineSpacing = 16 '行距为“固定值”的“12磅”
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True '用连字符号连接
.FirstLineIndent = CentimetersToPoints(0)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
.MirrorIndents = False
.TextboxTightWrap = wdTightNone
.AutoAdjustRightIndent = True
.DisableLineHeightGrid = False
.FarEastLineBreakControl = True
.WordWrap = True
.HangingPunctuation = True
.HalfWidthPunctuationOnTopOfLine = False
.AddSpaceBetweenFarEastAndAlpha = True
.AddSpaceBetweenFarEastAndDigit = True
.BaseLineAlignment = wdBaselineAlignAuto
End With
' 清除原有的段落底纹
Selection.ParagraphFormat.Shading.BackgroundPatternColor = wdColorAutomatic
End Sub
Sub table_100()
'
' table_100 宏
'
'
Dim tempTable As Table
Application.ScreenUpdating = False
'判断文档是否被保护
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
MsgBox "文档已保护,此时不能选中多个表格!"
Exit Sub
End If
'删除所有可编辑的区域
ActiveDocument.DeleteAllEditableRanges wdEditorEveryone
'添加可编辑区域
For Each tempTable In ActiveDocument.Tables
tempTable.Range.Editors.Add wdEditorEveryone
tempTable.PreferredWidthType = wdPreferredWidthPercent
tempTable.PreferredWidth = 100
Next
'选中所有可编辑区域
ActiveDocument.SelectAllEditableRanges wdEditorEveryone
'删除所有可编辑的区域
ActiveDocument.DeleteAllEditableRanges wdEditorEveryone
Application.ScreenUpdating = True
End Sub
来个效果:

利用word的VBA,为代码统一表格宽度,底色及行号的更多相关文章
- js获取表格视图所选行号的ids
实例化数组 遍历所选行push到数组中 将数组join转换为以,分割的字符串 /*获取指定id的datagrid的表格视图的选择的ids*/ function getDataGridSelectRow ...
- ExtJS表格——行号、复选框、选择模型
本篇的内容是为表格添加行号,和复选框,最后谈一下Ext的选择模型.内容比较简单,就直接上代码了.一. 设置行号 行号的设置主要问题在于删除某一行后需要重新计算行号 Ext.onReady(fun ...
- 解决代码着色组件SyntaxHighlighter行号显示问题
SyntaxHighlighter是根据代码中的换行符分配行号的.但是,如果一行代码或者注释比较长,在页面显示时需要分成多行显示,这时行号就对不上了.如下图: 通过下面的css强制不换行,可以避开这个 ...
- pycharm 设置字体大写和显示代码行号
打开pycharm,我们看到左边是没有行号显示的. 在工具栏中点击扳手的标志,打开. 找到 Ide-setting ——>Editor ——>Apperance ——> ...
- Java利用poi生成word(包含插入图片,动态表格,行合并)
转(小改): Java利用poi生成word(包含插入图片,动态表格,行合并) 2018年12月20日 09:06:51 wjw_11093010 阅读数:70 Java利用poi生成word(包含插 ...
- 【3】利用Word模板生成文档的总结
阅读目录 Word二次开发概况 使用DsoFramer进行开发 使用Interop进行开发 打开.关闭和写入操作 批量替换文本 遍历段落替换文本 查找后逐个替换文本 结论 在各类应用系统开发中,和Wo ...
- 利用模板导出文件(二)之jacob利用word模板导出word文件(Java2word)
https://blog.csdn.net/Fishroad/article/details/47951061?locationNum=2&fps=1 先下载jacob.jar包.解压后将ja ...
- Word批量设置表格宽度自动适应页面宽度
怎么批量修改Word表格的宽度呢.Word表格可根据窗口自动调整表格宽度,使得所有的表格宽度和页面宽度一样. 当页面设置了新的页边距后,所有的表格都需要调整新的宽度.或者文档中有许多大大小小的表格,希 ...
- Word:表格前添加新行 + 删除表格后的空行
本文适用于Word 2007 + Windows 7,造冰箱的大熊猫@cnblogs 2018/8/3 近日新学(百度到)两条新Word操作,记录下来以备查询 1.在表格前添加新行 场景:有没有遇到过 ...
随机推荐
- poj3468 A Simple Problem with Integers(线段树/树状数组)
Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. On ...
- 【刷题】LOJ 2587 「APIO2018」铁人两项
题目描述 比特镇的路网由 \(m\) 条双向道路连接的 \(n\) 个交叉路口组成. 最近,比特镇获得了一场铁人两项锦标赛的主办权.这场比赛共有两段赛程:选手先完成一段长跑赛程,然后骑自行车完成第二段 ...
- Linux上安装node和npm
说明:最近工作中需要用到react前端框架使得可以前后分离,在安装react之前呢我是需要先安装node,和npm的 由于npm是依赖于node 的,所以我这边只要安装了node后,npm也就安装完成 ...
- Git基本知识
一,安装 Ubuntu安装git:sudo apt-get install git-core Centos安装git:yum install git-core 二,配置身份---在提交代码时可以辨别身 ...
- C#基础概念
1. 面向对象的思想主要包括:继承 多态 封装 ● 封装:用抽象的数据类型将数据和基于数据的操作封装在一起,数据被保护在抽象数据类型内部. ● 继承:子类拥有父类的所有 ...
- 安装hadoop1.2.1(参考hadoop实战第二版)
准备: 安装jdk和ssh. 1. 官网下载hadoop1.2.1 hadoop-1.2.1.tar.gz http://hadoop.apache.org/releases.html 2. 解压到/ ...
- 【CSS】定义元素的位置
CSS定义元素的位置html元素的position属性,有4个属性值,分别是static.relative.fixed.absolute static: 1.默认值,一般不显式设置为static 2. ...
- Hive SQL 编译过程
转自:http://www.open-open.com/lib/view/open1400644430159.html Hive跟Impala貌似都是公司或者研究所常用的系统,前者更稳定点,实现方式是 ...
- Spark记录-Scala数组/List/Map/Set
import Array._ import scala.collection.mutable.Set object DataStructure { def main(args:Array[String ...
- Spark记录-spark介绍
Apache Spark是一个集群计算设计的快速计算.它是建立在Hadoop MapReduce之上,它扩展了 MapReduce 模式,有效地使用更多类型的计算,其中包括交互式查询和流处理.这是一个 ...