|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
你试试,见附件。- Sub ReadFromWord()
- Dim oWordApp As Object, oDoc As Object, txt$
- Dim myPath$, MyName$, k%, Result(1 To 1000, 1 To 5)
-
- On Error Resume Next
- Range("A2:E2000").ClearContents
- myPath = ThisWorkbook.Path & ""
- MyName = Dir(myPath & "*.doc*")
- Set oWordApp = CreateObject("Word.Application")
- Do While MyName <> ""
- If InStr(1, MyName, "项目") Then
- Set oDoc = GetObject(myPath & MyName)
- txt = oDoc.Range.Text
- oDoc.Close True
-
- k = k + 1
- Result(k, 1) = k
- Result(k, 2) = RegxFind(txt, "(.*)竞争性谈判纪要", 0)
- Result(k, 3) = RegxFind(txt, "([A-Z]{4}-\d{4}-\d{2}-\d{3})", 0)
- Result(k, 4) = RegxFind(txt, "中标人为(.*)。", 0)
- Result(k, 5) = RegxFind(txt, "(\d+\.?\d*)元作为最终报价", 0)
- End If
- MyName = Dir
- Loop
- Range("A2").Resize(k, 5) = Result
- Set oWordApp = Nothing
- End Sub
- Function RegxFind(strValue As String, strFind As String, Num As Integer) As String
- Dim RegX As Object, objMatchs As Object
- Dim strTemp As String
-
- Set RegX = CreateObject("vbscript.regexp")
- RegX.Pattern = strFind
-
- Set objMatchs = RegX.Execute(strValue)
- strTemp = objMatchs(0).SubMatches(Num)
-
- Set RegX = Nothing
- RegxFind = strTemp
- End Function
复制代码
|
评分
-
6
查看全部评分
-
|