VB将数据导出到word的问题

2024-11-29 04:33:42
推荐回答(1个)
回答(1):

Private Sub Command1_Click()
Dim wd As New Word.Application
wd.Documents.Add DocumentType:=wdNewBlankDocument
With wd.Selection
.Font.Spacing = 2
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Font.Size = 16
.Font.Name = "宋体"
.Font.Bold = True
.ParagraphFormat.LineSpacingRule = wdLineSpaceSingle
.Font.Spacing = 0
.TypeText label1.Caption
.Font.Bold = False
.TypeParagraph
.ParagraphFormat.Alignment = wdAlignParagraphJustify
.Font.Size = 10
.TypeText text1.Text & text2.Text
wd.ActiveDocument.Tables.Add Range:=wd.Selection.Range, NumRows:=mshflexgrid1.Rows, NumColumns _
:=10, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed
For i = 1 To mshflexgrid1.Rows
For j = 1 To 10
.Tables(1).Cell(i, j).Range.Text = mshflexgrid1.textmatrix(i - 1, j - 1)
Next j
Next i
.EndKey Unit:=wdStory
.Font.Color = wdColorRed
.TypeText text3.Text & vbTab & vbTab & vbTab & text4.Text
.TypeParagraph
.Font.Color = wdColorAutomatic
.TypeText text5.Text & vbTab & vbTab & vbTab & text6.Text
End With
wd.Visible = True
wd.ShowMe
Set wd = Nothing
End Sub