|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
另一个思路
- Sub ReadFromWord()
- Dim oWordApp As Object, oDoc As Object, txt$
- Dim myPath$, MyName$, k%, tempTxt$, Result(1 To 2000, 1 To 7) As String
- Dim j%, pNum%, arr, JD%
-
- 'On Error Resume Next
- Range("A2:G2000").ClearContents
- myPath = ThisWorkbook.Path & ""
- MyName = Dir(myPath & "*.doc*")
- Set oWordApp = CreateObject("Word.Application")
- Set oDoc = GetObject(myPath & MyName)
- pNum = oDoc.Paragraphs.Count
-
- For i = 1 To pNum
- txt = oDoc.Paragraphs(i).Range.Text
- If InStr(1, txt, "房屋安全鉴定报告") Then k = k + 1
- If InStr(1, txt, "户主姓名") > 0 Then
- tempTxt = oDoc.Paragraphs(i - 1).Range.Text
- arr = Split(tempTxt, ":")
- Result(k, 2) = Trim(Left(arr(1), InStr(1, arr(1), "鉴") - 1))
- Result(k, 1) = Trim(arr(2))
- Result(k, 3) = oDoc.Paragraphs(i + 1).Range.Text
- End If
-
- If InStr(1, txt, "第一次鉴定") Then JD = 1
- If InStr(1, txt, "第二次鉴定") Then JD = 2
-
- If InStr(1, txt, "建筑结构") Then
- Result(k, 2 + JD * 2) = oDoc.Paragraphs(i + 1).Range.Text
- End If
-
- If InStr(1, txt, "房屋危险等级评定") Then
- Result(k, 5) = oDoc.Paragraphs(i + 1).Range.Text
- End If
-
- If InStr(1, txt, "房屋综合等级") Then
- Result(k, 7) = oDoc.Paragraphs(i + 1).Range.Text
- End If
- Next
-
- For j = 3 To 7
- For i = 1 To k
- Result(i, j) = Left(Result(i, j), Len(Result(i, j)) - 1)
- Next
- Next
-
- Range("A2").Resize(k, 7) = Result
-
- oDoc.Close True
- oWordApp.Quit
- Set oWordApp = Nothing
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|