VB6 中打开word文件并读出文件中某几行的内容,在text文本框中显示
最近刚学习VB,想要在VB6 中打开word文件并读出文件中某几行的内容(有图片文字、字母和数字),在text文本框中显示,请教师傅们如何实现,最好有完全代码和注释,先跪谢啦!
程序代码:
Option Explicit Dim wApp As New Word.Application Dim wDoc As Word.Document Private Sub Command1_Click() Set wDoc = wApp.Documents.Open("C:\1.doc") Dim i As Long Dim Data As String Data = "" For i = 1 To wDoc.Words.Count Data = Data & wDoc.Words.Item(i) Next Dim Arr As Variant Arr = Split(Data, Chr(13)) If UBound(Arr) > 0 Then Text1.Text = Arr(1) '如果有第二行则读取第二行 If UBound(Arr) > 3 Then Text1.Text = Arr(4) '如果有第五行则读取第五行 wDoc.Close wApp.quit Set wDoc = Nothing Set wApp = Nothing End Sub