从结构相同的多个WORD文档中提取信息到EXCEL:
Sub test()
Dim myword, thispath, mydoc, s, s1, tm, r&
Set myword = CreateObject("word.application")
myword.Visible = True
thispath = ThisWorkbook.Path & "\"
mydoc = Dir(thispath & "*.doc")
Do While mydoc <> ""
r = r + 1
With myword
.documents.Open thispath & mydoc
.Selection.Find.MatchWildcards = True
'查找设区市
s = "设 区 市": s1 = "^13"
If .Selection.Find.Execute(s & "*" & s1) Then
tm = .Selection.Text
tm = Replace(Replace(Replace(tm, s, ""), " ", ""), Chr(13), "")
Cells(r + 2, 1) = tm: tm = ""
.Selection.MoveRight Unit:=1, Count:=1
End If
'查找学校行政区划
s = "学 校 行 政 区 划": s1 = "^13"
If .Selection.Find.Execute(s & "*" & s1) Then
tm = .Selection.Text
tm = Replace(Replace(Replace(tm, s, ""), " ", ""), Chr(13), "")
Cells(r + 2, 2) = tm: tm = ""
.Selection.MoveRight Unit:=1, Count:=1
End If
'查找工作单位
s = "工 作 单 位": s1 = "^13"
If .Selection.Find.Execute(s & "*" & s1) Then
tm = .Selection.Text
tm = Replace(Replace(Replace(tm, s, ""), " ", ""), Chr(13), "")
Cells(r + 2, 3) = tm: tm = ""
.Selection.MoveRight Unit:=1, Count:=1
End If
'查找姓名
s = "姓 名": s1 = "^13"
If .Selection.Find.Execute(s & "*" & s1) Then
tm = .Selection.Text
tm = Replace(Replace(Replace(tm, s, ""), " ", ""), Chr(13), "")
Cells(r + 2, 4) = tm: tm = ""
.Selection.MoveRight Unit:=1, Count:=1
End If
'读取表格1
With .activedocument.Tables(1)
Cells(r + 2, 5) = Replace(Replace(.cell(1, 4), Chr(7), ""), Chr(13), "")
Cells(r + 2, 6) = Replace(Replace(.cell(1, 6), Chr(7), ""), Chr(13), "")
Cells(r + 2, 7) = Replace(Replace(.cell(2, 2), Chr(7), ""), Chr(13), "")
Cells(r + 2, 8) = Replace(Replace(.cell(2, 4), Chr(7), ""), Chr(13), "")
Cells(r + 2, 9) = Replace(Replace(.cell(3, 2), Chr(7), ""), Chr(13), "")
Cells(r + 2, 10) = Replace(Replace(.cell(3, 4), Chr(7), ""), Chr(13), "")
Cells(r + 2, 11) = "'" & Replace(Replace(.cell(4, 2), Chr(7), ""), Chr(13), "")
Cells(r + 2, 12) = Replace(Replace(.cell(4, 4), Chr(7), ""), Chr(13), "")
Cells(r + 2, 13) = Replace(Replace(.cell(5, 4), Chr(7), ""), Chr(13), "")
Cells(r + 2, 14) = "'" & Replace(Replace(.cell(6, 2), Chr(7), ""), Chr(13), "")
Cells(r + 2, 15) = Replace(Replace(.cell(6, 4), Chr(7), ""), Chr(13), "")
Cells(r + 2, 16) = Replace(Replace(.cell(7, 2), Chr(7), ""), Chr(13), "")
Cells(r + 2, 17) = Replace(Replace(.cell(7, 4), Chr(7), ""), Chr(13), "")
Cells(r + 2, 18) = Replace(Replace(.cell(8, 2), Chr(7), ""), Chr(13), "")
Cells(r + 2, 19) = Replace(Replace(.cell(9, 2), Chr(7), ""), Chr(13), "")
Cells(r + 2, 20) = "'" & Replace(Replace(.cell(10, 2), Chr(7), ""), Chr(13), "")
Cells(r + 2, 21) = "'" & Replace(Replace(.cell(10, 4), Chr(7), ""), Chr(13), "")
End With
'-------------------------------------------------------------
.documents.Close False
End With
mydoc = Dir
Loop
myword.Quit
End Sub
30年荣誉证书 - 副本.rar
(56.54 KB, 下载次数: 51)
|