我需要帮助创建查找和替换字符串宏,以便它可以在文件夹中的所有文件中查找和替换字符串。
例如 fofler ="C:\ifolder\"
文件列表 ="*.xlsx"
到目前为止,我只能对一个文件执行此操作,我需要对文件夹中的所有文件执行此操作
Sub ReplaceStringInFile()
Dim sBuf As String
Dim sTemp As String
Dim iFileNum As Integer
Dim sFileName As String
' Edit as needed
sFileName = "C:\macro\test.txt"
iFileNum = FreeFile
Open sFileName For Input As iFileNum
Do Until EOF(iFileNum)
Line Input #iFileNum, sBuf
sTemp = sTemp & sBuf & vbCrLf
Loop
Close iFileNum
sTemp = Replace(sTemp, "THIS", "THAT")
iFileNum = FreeFile
Open sFileName For Output As iFileNum
Print #iFileNum, sTemp
Close iFileNum
End Sub