- Set WordApp = CreateObject("word.application")
- Set SHX = Worksheets("Sheet1")
- ARX = Split("1,1,1,6", ",") '//所在Word表格 行数,个数和顺序和Excel列对应
- BRX = Split("3,5,7,3", ",") '//所在Word表格 列数
- CRX = Split("6,9,10,11", ",") '//在Excel中放到第几列
-
- FileArr = FileAllArr(ThisWorkbook.Path, "*.DOC?", ThisWorkbook.Name, True, False)
- For i = 0 To UBound(FileArr)
-
- WordApp.Visible = False '关闭word文档的显示
- Set Worddoc = WordApp.Documents.Open(FileArr(i))
- Set WordTable = Worddoc.Tables(1) '指向第一张WORD表格
-
- Rem 每个需要的单元格
- For X = 0 To UBound(ARX)
- Set Cell = WordTable.Cell(Val(ARX(X)), Val(BRX(X)))
- If Not Cell Is Nothing Then '如果单元格存在
- SHX.Cells(i + 2, Val(CRX(X))).Value = Replace(Replace(Replace(Replace(Cell.Range.Text, Chr(7), ""), Chr(10), ""), Chr(13), ""), vbCrLf, "")
- End If
- Next
-
- Rem 搜索:培训费 2000 收款人
- Set Cell = WordTable.Cell(9, 2)
- Str费用 = Replace(Replace(Replace(Replace(Cell.Range.Text, Chr(7), ""), Chr(10), ""), Chr(13), ""), vbCrLf, "")
- SHX.Cells(i + 2, 21).Value = GetRegStr(Str费用, "[0-9.]+", 0)
-
- Rem 南山 福田 龙华 宝安 龙岗班
- STR1 = "南山,福田,龙华,宝安,龙岗班"
- With Worddoc.Content.Find
- .Highlight = True
- Do While .Execute
- Debug.Print "|" & .Parent.Text & "|"
- If InStr(STR1, Replace(Replace(.Parent.Text, "(", ""), " ", "")) > 0 Then
- SHX.Cells(i + 2, 23).Value = Replace(Replace(.Parent.Text, "(", ""), " ", "")
- Exit Do
- End If
- Loop
- End With
-
- WordApp.Visible = True '关闭word文档的显示
- Worddoc.Close False
- Next
- WordApp.Quit
- Set Worddoc = Nothing
复制代码 |