注册 登录
编程论坛 VB.NET论坛

请教大家以下,我写生成word文档,里面生成了表格,表格里的内容都赋值了,现在要在表格下方写其他内容,怎么写都是在表格第1行里。

dushuzai 发布于 2017-11-25 00:56, 1941 次点击
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
2 回复
#2
xyxcc1772017-11-25 10:39
关键是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
#3
dushuzai2017-11-28 13:02
回复 2楼 xyxcc177
感谢大神 ...
1