下面代码可以实现删除指定的字符行,不过如果记录太多速度上会有点慢。不知各位有没有其它更好的方法来实现?
Sub Format_DelLine()
Dim txtFile As String, strDel As String, txtLine As String
Dim objFSO As Object, objFile As Object
On Error Resume Next
tbPath = "D:\Business\stockinventory.txt"
strDel = "Stock Inventory Report"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(tbPath, 1)
Do Until objFile.AtEndOfStream
txtLine = objFile.Readline
If txtLine <> strDel Then
txtFile = txtFile & txtLine & vbCrLf
End If
Loop
objFile.Close
Set objFile = objFSO.Createtextfile(tbPath, 1)
objFile.Writeline txtFile
objFile.Close
Set objFile = Nothing
Set objFSO = Nothing
End Sub