| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1358 人关注过本帖
标题:请教大家以下,我写生成word文档,里面生成了表格,表格里的内容都赋值了, ...
只看楼主 加入收藏
dushuzai
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2017-11-24
结帖率:0
收藏
已结贴  问题点数:20 回复次数:3 
请教大家以下,我写生成word文档,里面生成了表格,表格里的内容都赋值了,现在要在表格下方写其他内容,怎么写都是在表格第1行里。
Dim myword As Word.Application
 Dim myd As Word.Document
 Dim myr As Word.Range
 Dim myr1 As Word.Range
 Dim mys As Word.Selection
 Dim myt As Word.Table

myword.Selection.EndKey unit:=wdStory '***************表格光标定位
Call myword.ActiveDocument.Tables.Add(myword.Application.Selection.Range, 16, 1, 1, 0) '***************建立表格



myword.ActiveDocument.Tables(1).Cell(1, 1).Range.InsertAfter "1"  '访问表格
myword.ActiveDocument.Tables(1).Cell(2, 1).Range.InsertAfter "2"
myword.ActiveDocument.Tables(1).Cell(3, 1).Range.InsertAfter "3"
myword.ActiveDocument.Tables(1).Cell(4, 1).Range.InsertAfter "4"
myword.ActiveDocument.Tables(1).Cell(5, 1).Range.InsertAfter "5"
myword.ActiveDocument.Tables(1).Cell(6, 1).Range.InsertAfter "6"
myword.ActiveDocument.Tables(1).Cell(7, 1).Range.InsertAfter "7"
myword.ActiveDocument.Tables(1).Cell(8, 1).Range.InsertAfter "8"
myword.ActiveDocument.Tables(1).Cell(9, 1).Range.InsertAfter "9"
myword.ActiveDocument.Tables(1).Cell(10, 1).Range.InsertAfter "10 "
myword.ActiveDocument.Tables(1).Cell(11, 1).Range.InsertAfter "11"
myword.ActiveDocument.Tables(1).Cell(12, 1).Range.InsertAfter "12"
myword.ActiveDocument.Tables(1).Cell(13, 1).Range.InsertAfter "13"
myword.ActiveDocument.Tables(1).Cell(14, 1).Range.InsertAfter "14"
myword.ActiveDocument.Tables(1).Cell(15, 1).Range.InsertAfter "15"
myword.ActiveDocument.Tables(1).Cell(16, 1).Range.InsertAfter "16"

myword.ActiveDocument.Tables(1).Cell(1, 1).Range.Paragraphs.Alignment = wdAlignParagraphCenter '定位表格居中

'*****表格字号
myword.ActiveDocument.Tables(1).Cell(1, 1).Range.Font.Size = 8
myword.ActiveDocument.Tables(1).Cell(2, 1).Range.Font.Size = 8
myword.ActiveDocument.Tables(1).Cell(3, 1).Range.Font.Size = 8
myword.ActiveDocument.Tables(1).Cell(4, 1).Range.Font.Size = 8
myword.ActiveDocument.Tables(1).Cell(5, 1).Range.Font.Size = 8
myword.ActiveDocument.Tables(1).Cell(6, 1).Range.Font.Size = 8
myword.ActiveDocument.Tables(1).Cell(7, 1).Range.Font.Size = 8
myword.ActiveDocument.Tables(1).Cell(8, 1).Range.Font.Size = 8
myword.ActiveDocument.Tables(1).Cell(9, 1).Range.Font.Size = 8
myword.ActiveDocument.Tables(1).Cell(10, 1).Range.Font.Size = 8
myword.ActiveDocument.Tables(1).Cell(11, 1).Range.Font.Size = 8
myword.ActiveDocument.Tables(1).Cell(12, 1).Range.Font.Size = 8
myword.ActiveDocument.Tables(1).Cell(13, 1).Range.Font.Size = 8
myword.ActiveDocument.Tables(1).Cell(14, 1).Range.Font.Size = 8
myword.ActiveDocument.Tables(1).Cell(15, 1).Range.Font.Size = 8
myword.ActiveDocument.Tables(1).Cell(16, 1).Range.Font.Size = 8

myword.ActiveDocument.Tables(1).Cell(12, 1).Range.Font.Color = vbRed '***颜色
myword.ActiveDocument.Tables(1).Cell(13, 1).Range.Font.Color = vbRed

myword.ActiveDocument.Tables(1).Cell(12, 1).Range.Font.Bold = True
myword.ActiveDocument.Tables(1).Cell(13, 1).Range.Font.Bold = True



myword.Selection.EndKey unit:=wdStory
myword.Selection.TypeParagraph

myr.Paragraphs.Alignment = wdAlignParagraphCenter
myr.InsertAfter "aaaa" & Chr(13)
myr.Font.Name = "宋体"
myr.Font.Size = 9
myr.Font.Underline = False
myr.Font.Bold = False
myr.Start = myr.End
搜索更多相关主题的帖子: word 表格 Tables Cell Size 
2017-11-24 22:49
dushuzai
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2017-11-24
收藏
得分:0 
抱歉。中间少了一段代码 ,光标定位上行。
On Error Resume Next

Set myword = CreateObject("Word.Application")
Set myd = myword.Documents.Add
Set myr = myd.Range(Start:=0, End:=0)
myr.Paragraphs.Alignment = wdAlignParagraphCenter
myr.InsertAfter "aaaa" & Chr(13)
myr.Font.Name = "宋体"
myr.Font.Size = 9
myr.Font.Underline = False
myr.Font.Bold = False
myr.Start = myr.End
2017-11-25 11:49
你的爱888
Rank: 2
等 级:论坛游民
帖 子:2
专家分:10
注 册:2017-11-25
收藏
得分:10 
62d24728c369759fc91d0f5fc6c8d3e6
2017-11-25 13:26
xyxcc177
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:26
帖 子:197
专家分:1249
注 册:2017-7-8
收藏
得分:10 
错误在 myr = myd.Range(Start:=0, End:=0),这句把光标定在myd的开最前面;你声明的对象都没有用,代码太繁
Dim myword As Word.Application
 Dim myd As Word.Document
 Dim myr As Word.Range
 Dim myr1 As Word.Range
 Dim mys As Word.Selection
 Dim myt As Word.Table

myword.Selection.EndKey unit:=wdStory '***************表格光标定位
set myt= myword.ActiveDocument.Tables.Add(myword.Application.Selection.Range, 16, 1, 1, 0) '***************建立表格

with myt
.Cell(1, 1).Range.InsertAfter "1"  '访问表格
.Cell(2, 1).Range.InsertAfter "2"
.Cell(3, 1).Range.InsertAfter "3"
......
end with


myword.ActiveDocument.Tables(1).Cell(1, 1).Range.Paragraphs.Alignment = wdAlignParagraphCenter '定位表格居中

'*****表格字号
......
myword.Selection.EndKey unit:=wdStory
myword.Selection.TypeParagraph
Set myr = myd.Range
myr.Paragraphs.Alignment = wdAlignParagraphCenter
myr.InsertAfter "aaaa" & Chr(13)
myr.Font.Name = "宋体"
myr.Font.Size = 9
myr.Font.Underline = False
myr.Font.Bold = False
myr.Start = myr.End
2017-11-25 13:34
快速回复:请教大家以下,我写生成word文档,里面生成了表格,表格里的内容都赋值 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014850 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved