我把TXT文件读出后,写到word文档中时,word显示出来是空的,我的代码如下:
Private Sub WordTable()
Dim wrdApp As New Word.Application
Dim doc As Word.Document
Dim sel As Word.Selection
Dim tbl As Word.Table
Dim i As Integer, j As Integer
Dim docname As String
Dim sTxt As String
Dim RawText() As String
wrdApp.Visible = True 'ÏÔʾApplication
call aaa()
sTxt = Archive.sÖ÷ËÍ + Archive.sÕýÎÄ + Archive.s·¢ÎĺŠ+ Archive.s·¢±¨µ¥Î»
RawText() = Split(sTxt, vbCrLf, -1)
wrdApp.Documents.Add 'Ìí¼ÓÎĵµ
docname = wrdApp.ActiveDocument.Name '»ñÈ¡ÎĵµÃû
Set doc = wrdApp.Documents(docname) '¸³µ±Ç°Îĵµ¸øDOC±äÁ¿
Set sel = wrdApp.Selection
'É趨WORDÎĵµµÄ×ÖÌåÊôÐÔ
With sel
.Font.Name = "ËÎÌå"
.Font.Size = 14
.Font.Bold = False
'.Borders = 2
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.InsertParagraphAfter
.EndOf
End With
写入word中
With tbl
For i = LBound(RawText()) To UBound(RawText())
For j = 0 To 24
.Cell(i, j).Range.Text = RawText(i)
Next j
Next i
End With
sel.GoToNext (wdGoToTable)
sel.Document.Range.InsertParagraphAfter
sel.Document.Range.InsertAfter RawText(i)
Set wrdApp = Nothing
End Sub
Private Sub WordTable()
Dim wrdApp As New Word.Application
Dim doc As Word.Document
Dim sel As Word.Selection
Dim tbl As Word.Table
Dim i As Integer, j As Integer
Dim docname As String
Dim sTxt As String
Dim RawText() As String
wrdApp.Visible = True 'ÏÔʾApplication
call aaa()
sTxt = Archive.sÖ÷ËÍ + Archive.sÕýÎÄ + Archive.s·¢ÎĺŠ+ Archive.s·¢±¨µ¥Î»
RawText() = Split(sTxt, vbCrLf, -1)
wrdApp.Documents.Add 'Ìí¼ÓÎĵµ
docname = wrdApp.ActiveDocument.Name '»ñÈ¡ÎĵµÃû
Set doc = wrdApp.Documents(docname) '¸³µ±Ç°Îĵµ¸øDOC±äÁ¿
Set sel = wrdApp.Selection
'É趨WORDÎĵµµÄ×ÖÌåÊôÐÔ
With sel
.Font.Name = "ËÎÌå"
.Font.Size = 14
.Font.Bold = False
'.Borders = 2
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.InsertParagraphAfter
.EndOf
End With
写入word中
With tbl
For i = LBound(RawText()) To UBound(RawText())
For j = 0 To 24
.Cell(i, j).Range.Text = RawText(i)
Next j
Next i
End With
sel.GoToNext (wdGoToTable)
sel.Document.Range.InsertParagraphAfter
sel.Document.Range.InsertAfter RawText(i)
Set wrdApp = Nothing
End Sub
sel.Document.Save
或者是
sel.Document.SaveAs ...