|
Option Explicit
Sub test()
Dim ar, br, cr, i&, j&, strTxt$, strFileName$, strPath$
Application.ScreenUpdating = False
ar = [A1].CurrentRegion.Value
br = Array(82, 95)
strPath = ThisWorkbook.Path & "\"
With CreateObject("VBScript.RegExp")
.Pattern = "[\d\.]+"
For i = 3 To UBound(ar)
strFileName = strPath & ar(i, 1) & ".b5r"
If Dir(strFileName) <> "" Then
strTxt = ReadFromTextFile(strFileName)
cr = Split(strTxt, vbCrLf)
For j = 0 To UBound(br)
If .test(cr(br(j))) Then
cr(br(j)) = .Replace(cr(br(j)), ar(i, j + 2))
End If
Next j
WriteToTextFile strFileName, Join(cr, vbCrLf)
End If
Next i
End With
Application.ScreenUpdating = True
Beep
End Sub
Function ReadFromTextFile$(ByVal strFullName$, Optional ByVal strCharSet$ = "UTF-8")
With CreateObject("ADODB.Stream")
.Type = 2
.Mode = 3
.Charset = strCharSet
.Open
.LoadFromFile strFullName
ReadFromTextFile = .ReadText
.Close
End With
End Function
Function WriteToTextFile(ByVal strFullName$, ByVal strTxt$, Optional ByVal strCharSet$ = "UTF-8")
With CreateObject("ADODB.Stream")
.Type = 2
.Mode = 3
.Charset = strCharSet
.Open
.WriteText strTxt
.SaveToFile strFullName, 2
.flush
.Close
End With
End Function
|
评分
-
1
查看全部评分
-
|