如何用VB在WORD中添加表格
我想用VB打开WORD并输出内容,如下图:现在的问题是文字我知道怎么写,但是不会插入表格;在下纯属自学,忘高手帮忙;我的代码如下:PublicmuluAsStringDi...
我想用VB打开WORD并输出内容,如下图:
现在的问题是文字我知道怎么写,但是不会插入表格;在下纯属自学,忘高手帮忙;我的代码如下:
Public mulu As StringDim myword As Word.ApplicationDim mydocument As Word.DocumentDim myrange As Word.RangeDim myselect As Word.SelectionDim mytable As Word.Table
Private Sub Command1_Click()On Error Resume Next
Set myword = CreateObject("word.application")
Set mydocument = myword.Documents.AddSet myrange = mydocument.Range(Start:=0, End:=0)
mydocument.Activatemyword.Visible = True
myrange.Paragraphs.Alignment = wdAlignParagraphCenterxumc = Text1.Textmyrange.InsertAfter Chr(13)myrange.InsertAfter xumc & Chr(13)myrange.InsertAfter "矿山恢复治理与环境保护与土地复垦方案" & Chr(13) & Chr(13) & Chr(13) & Chr(13) & Chr(13) & Chr(13) & Chr(13) & Chr(13) & Chr(13) & Chr(13) & Chr(13) & Chr(13) & Chr(13) & Chr(13) & Chr(13)myrange.Font.Name = "黑体"myrange.Font.Size = 22
myrange.Start = myrange.Endmyrange.Paragraphs.Alignment = wdAlignParagraphCenteryzdw = Text2.Textmyrange.InsertAfter "业主单位:" & yzdw & Chr(13)myrange.Font.Name = "黑体"myrange.Font.Size = 16
.................
省去一部分代码 展开
现在的问题是文字我知道怎么写,但是不会插入表格;在下纯属自学,忘高手帮忙;我的代码如下:
Public mulu As StringDim myword As Word.ApplicationDim mydocument As Word.DocumentDim myrange As Word.RangeDim myselect As Word.SelectionDim mytable As Word.Table
Private Sub Command1_Click()On Error Resume Next
Set myword = CreateObject("word.application")
Set mydocument = myword.Documents.AddSet myrange = mydocument.Range(Start:=0, End:=0)
mydocument.Activatemyword.Visible = True
myrange.Paragraphs.Alignment = wdAlignParagraphCenterxumc = Text1.Textmyrange.InsertAfter Chr(13)myrange.InsertAfter xumc & Chr(13)myrange.InsertAfter "矿山恢复治理与环境保护与土地复垦方案" & Chr(13) & Chr(13) & Chr(13) & Chr(13) & Chr(13) & Chr(13) & Chr(13) & Chr(13) & Chr(13) & Chr(13) & Chr(13) & Chr(13) & Chr(13) & Chr(13) & Chr(13)myrange.Font.Name = "黑体"myrange.Font.Size = 22
myrange.Start = myrange.Endmyrange.Paragraphs.Alignment = wdAlignParagraphCenteryzdw = Text2.Textmyrange.InsertAfter "业主单位:" & yzdw & Chr(13)myrange.Font.Name = "黑体"myrange.Font.Size = 16
.................
省去一部分代码 展开
1个回答
展开全部
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=50, NumColumns:= _
4, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
If .Style <> "网格型" Then
.Style = "网格型"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = False
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = False
.ApplyStyleRowBands = True
.ApplyStyleColumnBands = False
End With
补充一下,可以用录制宏的方法查看代码学习编程,我也是在学习中
4, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
If .Style <> "网格型" Then
.Style = "网格型"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = False
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = False
.ApplyStyleRowBands = True
.ApplyStyleColumnBands = False
End With
补充一下,可以用录制宏的方法查看代码学习编程,我也是在学习中
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询