在你的代码后面加一个过程
1、打开那个文本文件
竹笛 00:08:15
2、移到到最后一行
3、delete
以下代码共参考,是一个删除指定行的函数
Private Sub CmdDeleteLine_Click()
Const MAX_PATH = 260
Const NAME_LEN = MAX_PATH + 80
Dim inname As String
Dim strlen As Integer
Dim outpath As String
Dim outname As String
Dim infile As Integer
Dim outfile As Integer
Dim one_line As String
Dim target As String
Dim deleted As Integer
On Error GoTo DeleteLineError
' Open the input file.
inname = FileText.Text
infile = FreeFile
Open inname For Input As infile
' Open the output file.
outpath = Space$(NAME_LEN)
strlen = GetTempPath(NAME_LEN, outpath)
If strlen = 0 Then
MsgBox "Error getting temporary file path."
Exit Sub
Else
outpath = Left$(outpath, strlen)
End If
outname = Space$(NAME_LEN)
If GetTempFileName(outpath, "tmp", _
0, outname) = 0 _
Then
MsgBox "Error getting temporary file name."
Exit Sub
End If
strlen = InStr(outname, vbNullChar) - 1
If strlen > 0 Then _
outname = Left$(outname, strlen)
outfile = FreeFile
Open outname For Output As outfile
MousePointer = vbHourglass
DoEvents
' Copy the file skipping lines containing the
' target.
deleted = 0
target = TargetText.Text
Do While Not EOF(infile)
Line Input #infile, one_line
If InStr(one_line, target) = 0 Then
Print #outfile, one_line
Else
deleted = deleted + 1
End If
Loop
' Close the files.
Close infile
Close outfile
' Delete the original file.
Kill inname
' Give the new file the old name.
Name outname As inname
MsgBox Format$(deleted) & " lines deleted."
DeleteLineError:
MousePointer = vbDefault
Exit Sub
End Sub
问题解决了:),谢谢笛子,谢谢andymark
andymark (2007-11-27 00:37:20)
你试试下面的方法是否可行
输出文本文件后,调用下面的代码
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim Fs, F, TS, S
Set Fs = CreateObject("Scripting.FileSystemObject")
Set F = Fs.OpenTextFile(CurrentProject.Path & "\" & "lhl.txt", _
ForReading, False, TristateUseDefault)
S = F.readall() '读取文本文件内容
S = Left(S, Len(S) - 2) '清除文本内容最后2个字符,也就是回车符
Set F = Fs.OpenTextFile(CurrentProject.Path & "\" & "lhl.txt", ForWriting, TristateFalse)
F.Write S '重新回写
F.Close
总记录:6篇 页次:1/1 9 1 :