@echo off
setlocal enabledelayedexpansion
set "directory=path\to\your\excel\files"
set "old_str=A"
set "new_str=B"
for /r "%directory%" %%f in (.xlsx) do (
powershell -Command "$excel = New-Object -ComObject Excel.Application; $workbook = $excel.Workbooks.Open('%%f'); foreach ($sheet in $workbook.Sheets) { foreach ($cell in $sheet.UsedRange.Cells) { if ($cell.Value2 -ne $null -and $cell.Value2 -is [String] -and $cell.Value2 -like '%old_str%*') { $cell.Value2 = $cell.Value2 -replace '%old_str%', '%new_str%' } } }; $workbook.Save(); $excel.Quit();"
)
echo Batch replacement completed.