VBA添加表格

Sub 添加表格()
‘
If MsgBox("要为所有表格添加列吗?", vbYesNo + vbQuestion) = vbYes Then
For i = 1 To ActiveDocument.Tables.Count

Dim myTable As Table
Set myTable = ActiveDocument.Tables(i)
myTable.Rows.Last.Select

Selection.InsertRowsBelow 1
Selection.Collapse Direction:=wdCollapseStart
Selection.TypeText Text:="实际结果"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="与期望结果一致"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="测试结果"
Selection.MoveRight Unit:=wdCell
Selection.Cells.Split NumRows:=1, NumColumns:=3, MergeBeforeSplit:=False
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="通过"
Selection.SelectCell
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Cells.VerticalAlignment = wdCellAlignVerticalCenter
Selection.SelectCell
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Cells.VerticalAlignment = wdCellAlignVerticalCenter
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="缺陷编号"
Selection.SelectCell
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Cells.VerticalAlignment = wdCellAlignVerticalCenter
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="备注"
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCharacter, Count:=3, Extend:=wdExtend
Selection.Cells.Merge
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="测试人"
Selection.MoveRight Unit:=wdCell
Selection.Cells.Split NumRows:=1, NumColumns:=3, MergeBeforeSplit:=False
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="XXX"
Selection.SelectCell
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Cells.VerticalAlignment = wdCellAlignVerticalCenter
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="测试日期"
Selection.SelectCell
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Cells.VerticalAlignment = wdCellAlignVerticalCenter
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="2016-4-18"
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.TypeText Text:="无"
Selection.SelectCell
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Cells.VerticalAlignment = wdCellAlignVerticalCenter
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=5
Selection.SelectCell
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Cells.VerticalAlignment = wdCellAlignVerticalCenter

Next
MsgBox ("完成")
Else
MsgBox ("任务取消")
End If
End Sub
时间: 2024-08-26 00:57:03

VBA添加表格的相关文章

OpenXml入门----给Word文档添加表格

下面将展示如何使用Openxm向Word添加表格. 代码中表头和数据我用的同一个TableRow来添加,其实可以通过TableHeader来,其实都一样.后面教程我会给出如何设置单元格样式.表头那一行可以自己通过设置样式来控制 代码如下: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Document

动态添加表格

1.表格包含的HTML DOM对象 2.Table对象 3.TableRow对象 4.TableCell对象 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml&qu

JQuery动态添加表格,然后动态删除不成功问题

背景: 自己做了一个测试网页,想动态添加表格,然后删除,按照网上的教程写完,发现点击"删除参数"按钮没用 源码: function addtr() { var trinfo = "<tr><td><input placeholder='参数名称' style='width: 80%'></td>" + "<td><input placeholder='参数值' style='width: 7

C# 如何添加表格到Word文档

表格是组织整理数据的一种重要手段,应在生活中的方方面面.在Word文档中将繁杂的文字表述内容表格化,能快速.直接地获取关键内容信息.那么,通过C#,我们也可以在Word文档中添加表格,这里将介绍两种不同的表格添加方法. 使用工具:Spire.Doc for .NET 使用方法:安装后,添加引用dll文件到项目中即可 表格添加方法一:动态地向Word添加表格行和单元格内容,需调用方法section. AddTable().table. AddRow和row. AddCell() using Sys

C#采用OpenXml给Word文档添加表格

本文实例讲述了C#采用OpenXml给Word文档添加表格的方法,是非常实用的操作技巧.分享给大家供大家参考.具体分析如下: 这里将展示如何使用Openxml向Word添加表格. 代码中表头和数据我们用的同一个TableRow来添加,其实可以通过TableHeader来,其实都一样.后面我们还会进一步给出如何设置单元格样式.表头那一行可以自己通过设置样式来控制 示例代码如下: using System; using System.Collections.Generic; using System

JS动态添加表格 一

利用document.createElement(),  appendChild()方法可以动态创建和添加表格 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml&q

[VBA]统计数据库表格总笔数

之前帮同事做过总笔数的查询 [SQL]检查数据库表格总笔数 改成VBA的版本 程序结构 表单(SubConnectString) Private Sub cmd_Confirm_Click() If txt_IP.Text = "" Or txt_Account.Text = "" Or txt_PWD.Text = "" Then MsgBox "请输入连线相关资讯" Exit Sub End If GetConnectSt

Java 在Word中添加表格、嵌套表格

表格作为一种可视化交流模式及组织.整理数据的方法,在各种场合及文档中应用广泛.常见的表格可包含文字.图片等元素,我们操作表格时可以插入图片.嵌套表格.写入文字及格式化表格样式等.下面,将通过Java编程在Word文档中创建表格并实现格式化操作,包括设置字体.字号.字体颜色.字体粗细等,设置单元格对齐方式.单元格背景色.单元格合并/拆分.表格边框样式.插入图片等等. 使用工具:Free Spire.Doc for Java (免费版)Jar文件获取及导入:方法1:通过官网下载文件包.下载后,解压文

VBA 添加日历控件的操作

近几天需要做一个VBA的宏,以方便在excel中选择格式化后日期,要求添加日历控件,并按照格式化进行输出,由于是第一次接触VBA,因此查询了一些资料,下面对自己所做的过程进行一下总结: 1.首先新建一个excel文档. 2.对excel文档添加添加日历控件,具体过程如下图: 插入其他控件中的日历控件,如下图: 添加完后如下图所示: 双击控件即可编写代码,代码如下 Private Sub Calendar1_Click() ActiveCell = Calendar1.Value        C