关于VB读取word中某一行的问题,求求各位高手帮我解决下!!!
请问怎么用VB获取word文档里面的某一行的内容,然后相应的赋给文本框。我之前是用的代码如下
Set wDoc = wApp.Documents.Open(App.Path & "\2.doc")
Dim i As Long
Dim Data As String
Data = ""
For i = 1 To wDoc.Words.Count
Data = Data & wDoc.Words.Item(i)
Next i
Dim Arr As Variant
Arr = Split(Data, Chr(13))
If Combo1.Text = "Crushing" And Text1.Text < 4 And Text1.Text <> 0 Then
Text2.Text = Arr(119)
Text3.Text = Arr(121)
Text4.Text = Arr(122)
ElseIf Combo1.Text = "Crushing" And Text1.Text >= 4 Then
Text2.Text = Arr(10)
Text3.Text = Arr(11)
Text4.Text = Arr(12)
End If
但是这样运行,太慢了,我的word里面有三百多行?请问有没有简单运行起来快速的方法!!求求各位了!
[解决办法]
Dim oWordApp As Object
Dim oDoc As Object
Dim strWord() As String
Set oWordApp = CreateObject("Word.Application")
Set oDoc = oWordApp.Documents.Open("C:\temp\123.doc", , True)
strWord = Split(oDoc.range.Text, Chr(13))
Text1 = strWord(1)
oDoc.Close True
oWordApp.Quit
Set oWordApp = Nothing
Set oDoc = Nothing
[解决办法]