|
westwindgg 发表于 2015-4-3 12:07
再顶下求助 - Sub tiqu()
- Dim dpath, Filename As String
- Dim wdapp As Word.Application
- Dim wddocument As Word.Document
- Dim arr(1 To 20), crr(1 To 100), drr(1 To 100)
- dpath = ThisWorkbook.Path
- Set wdapp = New Word.Application
- Application.ScreenUpdating = False
- Filename = Dir(dpath & "\*.doc")
- On Error Resume Next
- Do While Filename <> ""
- Set wddocument = wdapp.Documents.Open(dpath & "" & Filename)
- With wddocument
- arr(1) = .Tables(1).Cell(1, 2).Range.Text
- arr(2) = .Tables(1).Cell(1, 4).Range.Text
- arr(3) = .Tables(1).Cell(2, 4).Range.Text
- arr(4) = .Tables(1).Cell(3, 2).Range.Text
- arr(5) = .Tables(2).Cell(5, 2).Range.Text
- arr(6) = .Tables(2).Cell(6, 2).Range.Text
- arr(7) = .Tables(2).Cell(7, 2).Range.Text
- arr(8) = .Tables(2).Cell(2, 2).Range.Text
- arr(9) = .Tables(2).Cell(3, 2).Range.Text
- arr(10) = .Tables(4).Cell(5, 2).Range.Text
- arr(11) = .Tables(5).Cell(1, 1).Range.Text
- arr(12) = .Tables(6).Cell(1, 1).Range.Text
- x = .Tables(4).Rows.Count '不规格表格找处目标入组人数
- For i = 10 To x
- str1 = Mid(.Tables(4).Cell(i, 1).Range.Text, 1, 6)
- If str1 = "目标入组人数" Then
- arr(15) = .Tables(4).Cell(i, 2).Range.Text
- arr(16) = .Tables(4).Cell(i + 1, 2).Range.Text
- i = x
- End If
- Next i
- x1 = .Tables(7).Rows.Count '不规格表格找机构
- For m = 7 To x1
- str1 = Replace(.Tables(7).Cell(m, 2).Range.Text, vbCr & "", "")
- If str1 = "机构名称" Then
- jig = x1 - m
- For w = 1 To jig
- crr(w) = Replace(.Tables(7).Cell(m + w, 2).Range.Text, vbCr & "", "")
- drr(w) = Replace(.Tables(7).Cell(m + w, 3).Range.Text, vbCr & "", "")
- Next
- Exit For
- End If
- Next m
- For i = 1 To 16
- arr(i) = Replace(arr(i), vbCr & "", "")
- Next
- End With
- With Sheet1
- r = .[a65536].End(xlUp).Row + 1
- For n = 1 To jig
- arr(13) = crr(n)
- arr(14) = drr(n)
- .Range("A" & r).Resize(1, 16) = arr
- r = r + 1
- Next
- End With
- wddocument.Close
- Filename = Dir()
- Loop
- Set wddocument = Nothing
- wdapp.Quit
- Set wdapp = Nothing
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|