现在下面的代码可以向WORD中插入一个1列12行的表格,并给每行表格插入数据,
Dim Wd As New Word.Application
Wd.Documents.Add DocumentType:=wdNewBlankDocument
Set oDoc = Wd.ActiveDocument
Set oTable = oDoc.Tables.Add(Range:=oDoc.Range(Start:=0, End:=0), NumRows:=12, NumColumns:=1)
iCount = 1
For Each oCell In oTable.Range.Cells
oCell.Range.InsertAfter "第 " & iCount & "单元格"
'If iCount Mod 6 = 0 Then oCell.Range.InsertAfter "跳出表格再在同插入一个空格,接着继续插入另一个同样大小表格"
iCount = iCount + 1
Next oCell
oTable.AutoFormat Format:=wdTableFormatColorful2, ApplyBorders:=True, ApplyFont:=True, ApplyColor:=True
'将光标移到最后
Wd.Selection.EndKey Unit:=wdStory
'插入分页符
Wd.Selection.InsertBreak Type:=wdPageBreak
Wd.Visible = True
Wd.ShowMe
Set Wd = NothingWORD中的输出结果:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
第 1单元格
第 2单元格
第 3单元格
第 4单元格
第 5单元格
第 6单元格
第 7单元格
第 8单元格
第 9单元格
第 10单元格
第 11单元格
第 12单元格
+++++++++++++++++++++++++++++++++++++++++++++++++++++++现在我想在WORD中同时输出两个同样大小的表格,而且中间要留空格
下面的我想要的结果,谢谢解答^_^+++++++++++++++++++++++++++++++++++++++++++++++++++++++第 1单元格 留两个空格 第 7单元格
第 2单元格 留两个空格 第 8单元格
第 3单元格 留两个空格 第 9单元格
第 4单元格 留两个空格 第 10单元格
第 5单元格 留两个空格 第 11单元格
第 6单元格 留两个空格 第 12单元格
Dim Wd As New Word.Application
Wd.Documents.Add DocumentType:=wdNewBlankDocument
Set oDoc = Wd.ActiveDocument
Set oTable = oDoc.Tables.Add(Range:=oDoc.Range(Start:=0, End:=0), NumRows:=12, NumColumns:=1)
iCount = 1
For Each oCell In oTable.Range.Cells
oCell.Range.InsertAfter "第 " & iCount & "单元格"
'If iCount Mod 6 = 0 Then oCell.Range.InsertAfter "跳出表格再在同插入一个空格,接着继续插入另一个同样大小表格"
iCount = iCount + 1
Next oCell
oTable.AutoFormat Format:=wdTableFormatColorful2, ApplyBorders:=True, ApplyFont:=True, ApplyColor:=True
'将光标移到最后
Wd.Selection.EndKey Unit:=wdStory
'插入分页符
Wd.Selection.InsertBreak Type:=wdPageBreak
Wd.Visible = True
Wd.ShowMe
Set Wd = NothingWORD中的输出结果:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
第 1单元格
第 2单元格
第 3单元格
第 4单元格
第 5单元格
第 6单元格
第 7单元格
第 8单元格
第 9单元格
第 10单元格
第 11单元格
第 12单元格
+++++++++++++++++++++++++++++++++++++++++++++++++++++++现在我想在WORD中同时输出两个同样大小的表格,而且中间要留空格
下面的我想要的结果,谢谢解答^_^+++++++++++++++++++++++++++++++++++++++++++++++++++++++第 1单元格 留两个空格 第 7单元格
第 2单元格 留两个空格 第 8单元格
第 3单元格 留两个空格 第 9单元格
第 4单元格 留两个空格 第 10单元格
第 5单元格 留两个空格 第 11单元格
第 6单元格 留两个空格 第 12单元格
For Each oCell In oTable.Range.Cells
oCell.Range.InsertAfter "第 " & iCount & "单元格"
现在就是这里不好表达
'If iCount Mod 6 = 0 Then oCell.Range.InsertAfter "跳出表格再在同插入一个空格,接着继续插入另一个同样大小表格"
iCount = iCount + 1
Next oCell
http://www.microsoft.com/china/msdn/archives/technic/tips/msword.asp