|
- Sub Test()
- Dim strFilePath As String, strTxt As String
- Dim objFS As Object, objTS As Object, objDic As Object
- Dim objReg As Object, strPat As String
- Dim objMatchs As Object, objMatch As Object
- Dim SH As Worksheet, arr As Variant, lngRow As Long
- strFilePath = Application.GetOpenFilename("文本,*.nc", , "打开")
- If strFilePath = "False" Then Exit Sub
-
- Set objFS = CreateObject("Scripting.FileSystemObject")
- Set objTS = objFS.OpenTextFile(strFilePath)
- strTxt = objTS.ReadAll '读出全部内容
- objTS.Close: Set objTS = Nothing
- Set objFS = Nothing
-
- strPat = "Toolname=(.*?),[\s\S]*?time:\s*([0-9\.]+)"
- Set objDic = CreateObject("Scripting.Dictionary")
- Set objReg = CreateObject("VBScript.RegExp")
- With objReg
- .Global = True
- .Pattern = strPat
- End With
-
- If objReg.Test(strTxt) Then
- Set objMatchs = objReg.Execute(strTxt)
- For Each objMatch In objMatchs
- objDic(objMatch.subMatches(0)) = objMatch.subMatches(1)
- Next
- End If
- Set objReg = Nothing
-
- Set SH = Sheets("C(Copper)")
- arr = SH.Range("A4:C27")
- For lngRow = LBound(arr) To UBound(arr)
- strTxt = arr(lngRow, 1)
- arr(lngRow, 3) = objDic(strTxt)
- Next
-
- SH.Range("A4:C27") = arr
- End Sub
复制代码 |
评分
-
2
查看全部评分
-
|