|
Sub 提取数据()
Application.ScreenUpdating = False
Dim FilePath As String
Dim n As Integer
Dim arr()
FilePath = ThisWorkbook.Path & "\" '"E:\文档\Word Demo\图片打印\9连环18件套" 'ChooseFolder
Dim WordApp As Object
Set WordApp = CreateObject("Word.Application") '新建Word对象
WordApp.Visible = False
f = Dir(FilePath & "*.doc*")
ReDim arr(1 To 10000, 1 To 5)
Do While f <> ""
n = n + 1
arr(n, 1) = n
Set WordD = WordApp.Documents.Open(FilePath & f)
With WordD.tables(1)
arr(n, 2) = Replace(.Cell(1, 2).Range.Text, Chr(13) & Chr(7), "") '建设单位
arr(n, 3) = Replace(.Cell(2, 2).Range.Text, Chr(13) & Chr(7), "") '工程名称
arr(n, 4) = Replace(.Cell(3, 2).Range.Text, Chr(13) & Chr(7), "") '建筑面积
xh = InStr(.Cell(4, 1).Range.Text, "实施单位在") + 5
arr(n, 5) = Mid(Replace(.Cell(4, 1).Range.Text, Chr(13) & Chr(7), ""), xh, 22) '工程造价
End With
f = Dir
Loop
Set WordD = Nothing
WordApp.Quit
[a1].CurrentRegion.Offset(1) = Empty
Range("a2").Resize(n, 5) = arr
Application.ScreenUpdating = True
MsgBox "完成"
End Sub
|
|