Sub 替换文件中一行(strSourceFile As String, strTargetFile As String, intRow As Long)
Dim filenum As Integer
Dim fileContents As String
Dim fileInfo() As String
Dim i As Integer
Dim j As Integer
Dim tmpDemData As String
filenum = FreeFile
Open strSourceFile For Binary As #filenum
fileContents = Space(LOF(filenum))
Get #filenum, , fileContents
Close filenum
fileInfo = Split(fileContents, vbCrLf)
'取出源文件行数,按照回车换行来分隔成数组
filenum = FreeFile
tmpDemData = ""
If Dir(strTargetFile, vbNormal) <> "" Then
Kill strTargetFile
End If
Dim Filestr() As String
Open strTargetFile For Append As #filenum
'循环每一行
For i = 0 To UBound(fileInfo) - 1
If i <> intRow - 1 Then
fileInfo(i)="你的内容"
Print #filenum, fileInfo(i)
End If
Next
Close #filenum
MsgBox "完毕"
End Sub
Private Sub Command1_Click()
替换文件中一行 "d:\aa.txt", "d:\bb.txt", 2
End Sub