我的算法部分代码:
Public Sub RepositionSlave(ByRef ws As Worksheet, ByVal limit As Long)
Dim inFileText As String
Dim outFileText As String
Dim inFileNo As Integer
Dim outFileNo As Integer
Dim inputfile As String
Dim outputfile As String
Dim OldPos As Long
Dim NewPos As Long
Dim length As Long
Dim i As Long
Dim writtenline As Long
outFileText = Space(limit)
inputfile = SlaveAsc
outputfile = ThisWorkbook.Path & "\" & OutputSlaveAsc
inFileNo = FreeFile
Open inputfile For Input As #inFileNo
outFileNo = FreeFile
Open outputfile For Output As #outFileNo
Do While Not EOF(inFileNo)
Line Input #inFileNo, inFileText
i = 2
While SlaveSheet.Cells(i, 2) <> ""
If SlaveSheet.Cells(i, 2) <> SlaveSheet.Cells(i - 1, 2) Then
OldPos = SlaveSheet.Cells(i, 3)
length = SlaveSheet.Cells(i, 4) - SlaveSheet.Cells(i, 3) + 1
NewPos = FindNewPos(SlaveSheet.Cells(i, 2))
'If NewPos <> -1 Then 'acc
Call ReplaceSpace(outFileText, NewPos, Mid(inFileText, OldPos, length))
'Mid(outFileText, NewPos, length) = Mid(inFileText, OldPos, length)
'End If 'acc
End If
i = i + 1
Wend
Print #outFileNo, outFileText
'writtenline = writtenline + 1
Loop
Close #inFileNo
Close #outFileNo
End Sub