这个简洁了吧。。。。。。。
- Sub ReadFromWord()
- Dim oDoc As Object
- Dim myPath$, MyName$, k%, JDDate$
-
- Range("A2:F2000").ClearContents
- myPath = ThisWorkbook.Path & ""
- MyName = Dir(myPath & "*.doc*")
- k = 1
- Do While MyName <> ""
- If InStr(1, MyName, "农户信用(经济)档案") Then
- Set oDoc = GetObject(myPath & MyName)
- k = k + 1
- Cells(k, 1) = k - 1
- With oDoc.Tables(1)
- Cells(k, 2) = Replace(.Cell(3, 2).Range.Text, Chr(7), "")
- Cells(k, 3) = Replace(.Cell(3, 6).Range.Text, Chr(7), "")
- Cells(k, 4) = Replace(.Cell(6, 2).Range.Text, Chr(7), "")
- Cells(k, 6) = Replace(.Cell(7, 2).Range.Text, Chr(7), "")
- End With
- JDDate = oDoc.Paragraphs(3).Range.Text
- JDDate = Split(Split(JDDate, " ")(0), ":")(1)
- Cells(k, 5) = JDDate
-
- oDoc.Close True
- End If
- MyName = Dir
- Loop
-
- End Sub
复制代码 注意myPath = ThisWorkbook.Path & "\"后面的"\"被网站自动删除了,需要手动加上。 |