word_宏示例
参考:https://jingyan.baidu.com/article/870c6fc3326588b03fe4beeb.html
内容自适应
Application.Browser.Target = wdBrowseTable For i = 1 To ActiveDocument.Tables.Count ActiveDocument.Tables(i).AutoFitBehavior (wdAutoFitContent) '根据内容自动调整表格 ActiveDocument.Tables(i).AutoFitBehavior (wdAutoFitWindow) '根据窗口自动调整表格 ActiveDocument.Tables(i).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter '水平居中 ActiveDocument.Tables(i).Range.ParagraphFormat.Alignment = wdCellAlignVerticalCenter '垂直居中 Next i
表格修改(清除表格内容)
Sub www()
'
' www 宏
'
'
Dim oDoc As Document
Dim oTable As Table
Dim cellLoop As Cell
Set oDoc = Documents.Open("F:\li\li\范式.docx")
Dim RowNum As Long, ColumnNum As Long, i As Long, oString As String
For Each oTable In oDoc.Tables
RowNum = oTable.Rows.Count
Column = oTable.Columns.Count
If Column >= 5 Then
For i = 1 To RowNum
oString = oTable.Cell(i, 4).Range.Text
If InStr(1, oString, "日期") = 1 Then
oTable.Cell(i, 5).Select
Selection.Delete
End If
Next
End If
Next
MsgBox "Finished!"
End Sub
表格修改(修改表格内容)
Sub www()
'
' www 宏
'
'
Dim oDoc As Document
Dim oTable As Table
Dim cellLoop As Cell
Set oDoc = Documents.Open("D:\Users\说明书.docx")
Dim RowNum As Long, ColumnNum As Long, i As Long, oString As String
For Each oTable In oDoc.Tables
RowNum = oTable.Rows.Count
Column = oTable.Columns.Count
If Column >= 5 Then
For i = 1 To RowNum
oString = oTable.Cell(i, 4).Range.Text
If InStr(1, oString, "日期") = 1 Then
oTable.Cell(i, 4).Select
Selection.TypeText Text:="DATE"
oTable.Cell(i, 5).Select
Selection.TypeText Text:="7"
End If
If InStr(1, oString, "字符串") = 1 Then
oTable.Cell(i, 4).Select
Selection.TypeText Text:="VARCHAR2"
End If
If InStr(1, oString, "整数") = 1 Then
oTable.Cell(i, 4).Select
Selection.TypeText Text:="NUMBER"
End If
If InStr(1, oString, "小数") = 1 Then
oTable.Cell(i, 4).Select
Selection.TypeText Text:="FLOAT"
End If Next
End If
Next
MsgBox "Finished!"
End Sub
比较表格中某列的值
Sub www()
'
' www 宏
'
'
Dim oDoc As Document
Dim oTable As Table
Dim cellLoop As Cell
Set oDoc = Documents.Open("F:\work\二审\详细设计参考文档\30个单位规范信息资源库docx\办公厅标准信息资源目录.docx")
Dim RowNum As Long, ColumnNum As Long, i As Long, oString As String
Dim Ostr2, Ostr3 As String
Ostr2 = "NULL"
Ostr3 = "NUL"
For Each oTable In oDoc.Tables
RowNum = oTable.Rows.Count
Column = oTable.Columns.Count
If Column = 4 Then
For i = 1 To RowNum
For j = 1 To Column
oString = oTable.Cell(i, j).Range.Text
If InStr(1, oString, "是否开放") = 1 Then
oStr = oTable.Cell(i, j).Next.Range.Text
If InStr(1, oStr, "否") = 1 Then
Ostr2 = "NO"
End If
If InStr(1, oStr, "是") = 1 Then
Ostr3 = "YES"
End If
'Selection.Delete
End If
Next
Next
End If
Next
MsgBox ("Ostr2:" + Ostr2)
MsgBox ("Ostr3:" + Ostr3)
MsgBox "Finished!"
End Sub
word_宏示例的更多相关文章
- Confluence 6 用户宏示例 - Color and Size
这个示例定义了如何向你宏中传递参数.我们将会创建一个字体样式宏,在这个宏中有 2 个参数,允许用户在这 2 个参数中指定宏中包含的字体的颜色大小. Macro name stylish Visibil ...
- Confluence 6 用户宏示例 - NoPrint
这个示例演示了如何创建一个用户宏,这个宏包括了在查看页面中显示的内容,但是不被打印. Macro name noprint Visibility Visible to all users in the ...
- Confluence 6 用户宏示例 - Hello World
下面示例显示了如何创建一个用户宏,在这个用户宏中显示文本 'Hello World!' 和任何用户在宏内容中输入的内容. Macro name helloworld Visibility Visibl ...
- 在 Excel 中如何使用宏示例删除列表中的重复项
概要:在 Microsoft Excel 中,可以创建宏来删除列表中的重复项.也可以创建宏来比较两个列表,并删除第二个列表中那些也出现在第一个(主)列表中的项目.如果您想将两个列表合并在一起,或者如果 ...
- Confluence 6 用户宏示例 - Formatted Panel
下面的用演示了如果还写一个用户宏,并在这个宏中创建一个格式化的面板,并且指定颜色.将会创建下面的面板: (Title) 注意:这个面板的标题为空,如果你没有给这个面板标题参数的话. Macro n ...
- CMake语法—普通变量与包含、宏(Normal Variable And Include、Macro)
目录 CMake语法-普通变量与包含.宏(Normal Variable And Include.Macro) 1 CMake普通变量与包含.宏示例 1.1 代码目录结构 1.2 根目录CMakeLi ...
- 【C语言】预处理、宏定义、内联函数 _
一.由源码到可执行程序的过程 1. 预处理: 源码经过预处理器的预处理变成预处理过的.i中间文件 1 gcc -E test.c -o test.i 2. 编译: 中间文件经过编译器编译形成.s的 ...
- 【C语言】预处理、宏定义、内联函数
一.由源码到可执行程序的过程 1. 预处理: 源码经过预处理器的预处理变成预处理过的.i中间文件 1 gcc -E test.c -o test.i 2. 编译: 中间文件经过编译器编译形成.s的汇编 ...
- velocity模板引擎学习(1)
velocity与freemaker.jstl并称为java web开发三大标签技术,而且velocity在codeplex上还有.net的移植版本NVelocity,(注:castle团队在gith ...
随机推荐
- MySQL中or与in
and和or mysql允许多个where子句,用and和or可以使用多个子句.and比or有更高的优先级.任何时候使用and和or都应使用圆括号操作符来明确的分组操作. in 圆括号在where子句 ...
- .Net培训班课程体系
.Net培训 第一部分:.Net基础 .Net基础:数据类型.变量.运算符.分支结构.循环结构.方法.反编译器.递归.递归算法的非递归优化: 面向对象:异常.封装继承多态.单例模式.装饰者设计模式.t ...
- 谈谈 SOA
为什么要 讨论 SOA 呢 ? 请参考我写的另一篇文章 <论 微服务 和 Entity Framework 对 数据 的 割裂> https://www.cnblogs.com/KS ...
- [转]SQL UNION 和 UNION ALL 操作符
SQL UNION 操作符 UNION 操作符用于合并两个或多个 SELECT 语句的结果集. 请注意,UNION 内部的 SELECT 语句必须拥有相同数量的列.列也必须拥有相似的数据类型.同时,每 ...
- Linux 操作系统下,安装软件 apt-get、yum 的区别
Linux 操作系统主要分为两大类: RedHat系列:Redhat.Centos.Fedora等: Debian系列:Debian.Ubuntu等. yum(Yellow dog Updater, ...
- TypeScript 之 三斜线指令
https://m.runoob.com/manual/gitbook/TypeScript/_book/doc/handbook/Triple-Slash%20Directives.html 一个三 ...
- linux curl 命令的使用
有时候需要内网访问接口地址,使用curl命令,带上-v参数 -v 参数可以显示一次 http 通信的整个过程,包括端口连接和 http request 头信息 curl -v http://172.9 ...
- 深入理解ASP.NET MVC(5)
系列目录 回顾 系列的前4节深入剖析了ASP.NET URL路由机制,以及MVC在此基础上是如何实现Areas机制的,同时涉及到inbound和outbound很多细节部分.第2节中提到MvcRout ...
- kindeditor在线编辑器的使用心得
1. 如何声明引用? <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> ...
- Maven+Eclipse+SparkStreaming+Kafka整合
版本号: maven3.5.0 scala IDE for Eclipse:版本(4.6.1) spark-2.1.1-bin-hadoop2.7 kafka_2.11-0.8.2 ...