'已经调试过的了 Option Explicit Private Sub Command1_Click() Dim FS As Object Set FS = CreateObject("Scripting.FileSystemObject") FindFile FS.GetFolder("D:\abc") Set FS = Nothing End Sub Private Sub FindFile(FD As Object) Dim FS As Object Set FS = CreateObject("Scripting.FileSystemObject") Dim FDS As Object, FL As Object For Each FDS In FD.SubFolders FindFile FDS Next For Each FL In FD.Files If UCase(FS.GetExtensionName(FL.Path)) = "TXT" Then ChangeFile FL End If Next Set FS = Nothing End Sub Private Sub ChangeFile(FL As Object) Dim FS As Object Set FS = CreateObject("Scripting.FileSystemObject") Dim TXT As Object Dim s As String s = FS.OpenTextFile(FL.Path).ReadAll If InStr(s, "yysj") Then s = Replace(s, "yysj", "abcd") Set TXT = FS.CreateTextFile(FL.Path, True) TXT.Write s TXT.Close End If Set FS = Nothing End Sub