| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1855 人关注过本帖
标题:请教大家以下,我写生成word文档,里面生成了表格,表格里的内容都赋值了, ...
只看楼主 加入收藏
dushuzai
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2017-11-24
结帖率:0
收藏
 问题点数:0 回复次数:2 
请教大家以下,我写生成word文档,里面生成了表格,表格里的内容都赋值了,现在要在表格下方写其他内容,怎么写都是在表格第1行里。
im 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-25 00:56
xyxcc177
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:26
帖 子:197
专家分:1249
注 册:2017-7-8
收藏
得分:0 
关键是myr对象没有明确

with myword.Selection
.Paragraphs.Alignment = wdAlignParagraphCenter
 .InsertAfter "aaaa" & Chr(13)
 .Font.Name = "宋体"
 .Font.Size = 9
 .Font.Underline = False
 .Font.Bold = False
 .Start = .End
end with
2017-11-25 10:39
dushuzai
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2017-11-24
收藏
得分:0 
回复 2楼 xyxcc177
感谢大神 ...
2017-11-28 13:02
快速回复:请教大家以下,我写生成word文档,里面生成了表格,表格里的内容都赋值 ...
数据加载中...
 
   



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

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