就是这样,给你代码看看:
'注意引用Microsoft Scripting Runtime
Option Explicit
Private Function deletestr(cfile As String, strdel As String) As Long
On Error GoTo myerr
Dim myfso As New FileSystemObject
Dim mystearm As TextStream
Set mystearm = myfso.OpenTextFile(cfile)
Dim s As String
s = mystearm.ReadAll
s = Replace(s, strdel, "")
Set mystearm = Nothing
Set mystearm = myfso.CreateTextFile(cfile, True)
mystearm.Write s
deletestr = 1
Exit Function
myerr:
deletestr = 0
MsgBox "error"
End Function
Private Sub Command1_Click()
Dim filename As String
filename = App.Path + "\123.txt"
Dim s As String
s = "456"
deletestr filename, s
End Sub