|
Sub test1()
Dim Myr%, i%, j%, m%, n%
Dim arr, brr(), Crr
Dim d As Object
Dim myname$, str$
Application.ScreenUpdating = False
Set d = CreateObject("Scripting.Dictionary")
myname = ThisWorkbook.Path & "\123.txt"
If Dir(myname) = vbNullString Then MsgBox myname: Exit Sub
Open myname For Input As #1
arr = Split(StrConv(InputB(LOF(1), 1), vbUnicode), vbNewLine)
Close #1
With Sheet1
Crr = .Range("a1:b" & .Range("a65536").End(xlUp).Row + 1)
End With
For j = 2 To UBound(Crr)
If Len(Crr(j, 2)) > 0 Then d(Crr(j, 1)) = Crr(j, 2)
Next j
nm = 0
For i = 0 To UBound(arr) '读取123.txt原有数据
If arr(i) = "[CCC]" Then
For j = i + 1 To UBound(arr)
If InStr(arr(j), "[") > 0 Then Exit For
k = Left(arr(j), 5)
If d.exists(k) Then arr(j) = k & "=" & d(k)
Next j
Exit For
End If
Next
Open ThisWorkbook.Path & "\456.txt" For Output As #1
Print #1, Join(arr, vbNewLine)
Close #1
Application.ScreenUpdating = True
End Sub
|
|