本帖最后由 mzbao 于 2019-3-21 12:44 编辑
Sub ReadFromWord()
Dim oDoc As Object, myPath$, MyName$, txt$
Dim RegX As Object, objMatchs As Object
Dim FileName$, FileNo$, i%, k%, fTxt$
myPath = ThisWorkbook.Path & "\"
MyName = Dir(myPath & "*.doc*")
Set RegX = CreateObject("vbscript.regexp")
RegX.Global = True
Do While MyName <> ""
If InStr(1, MyName, "审计报告") Then
Set oDoc = GetObject(myPath & MyName)
txt = oDoc.Range.Text
oDoc.Close True
txt = Replace(txt, Chr(13), "@")
RegX.Pattern = "[^@]+@[^@]+@+(中划时代〔\d+〕专审字第\d+号)"
Set objMatchs = RegX.Execute(txt)
For i = 0 To objMatchs.Count - 1
fTxt = objMatchs(i).Value
FileNo = Mid(fTxt, InStrRev(fTxt, "@") + 1)
FileName = Replace(Replace(fTxt, FileNo, ""), "@", "")
k = k + 1
Cells(1 + k, 1) = k
Cells(1 + k, 2) = FileName
Cells(1 + k, 3) = FileNo
Next
End If
MyName = Dir
Loop
Set oDoc = Nothing
End Sub |