You're not opening new files. You just loop through folder but all Cell.Replace statements are executed on your current worksheet. Use this in your loop:
Workbooks.Open Filename:= ...
Pergunta
I'm trying to make a simple action (for example replace "," by ".") to several excel files into one folder at the same time. A same kind of problems has already been solved here. But the solution doesn't work in my case:
Sub LoopThroughFiles()
Dim FolderPath As String, FileName As String
FolderPath = "C:\my_folder\"
FileName = Dir(FolderPath & "*.xlsx")
While (file <> "")
Workbooks.Open(FolderPath & FileName)
Cells.Replace What:=",", Replacement:=".", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Workbooks(FileName).Close SaveChanges:=True
file = Dir
Wend
End Sub
The macro works for my current file opened but not for the other present in my folder. Do you have any idea of how I could fix that?
Thanks for helping!
Solução
You're not opening new files. You just loop through folder but all Cell.Replace statements are executed on your current worksheet. Use this in your loop:
Workbooks.Open Filename:= ...