|
本帖最后由 爱疯 于 2016-5-26 11:39 编辑
从多个word文档里提取word文档页眉上的数据和应该怎么写代码?(详见附件指令单)(红色文字部分是需要提取的数据)
比如:excel表格里需要的数据是页眉上的“编号:xxxxxx”+责任人:“xxxx”+事由:“xxxxxxxxx”也是一行一个文档数据,代码该怎么写?
谢谢了[em44]
- Sub Macro1()
- mypath = ThisWorkbook.Path & ""
- Set wd = CreateObject("Word.Application")
- wj = Dir(mypath & "*.doc"): n = 1
- Do While wj <> ""
- n = n + 1: Cells(n, 1) = n - 1
- With wd.Documents.Open(mypath & wj)
- x = Split(.Range.Text, vbCr)
- Cells(n, 2) = Mid(.Sections(1).Headers(1).Range.Text, 4)
- For i = 0 To UBound(x)
- If x(i) Like "主送部门责任人:*" Then
- y = Split(x(i), "抄送")(0)
- Cells(n, 4) = Mid(y, 10)
- End If
- If x(i) Like "事由:*" Then
- Cells(n, 3) = Mid(x(i), 4)
- Exit For
- End If
- Next
- .Close False
- End With
- wj = Dir
- Loop
- wd.Quit
- End Sub
复制代码
|
|