PowerShell ISEを開き記述し、実行したいフォルダに保存する
# Excel アプリケーションオブジェクトを作成
$excel = New-Object -ComObject Excel.Application
$excel.Visible = $false
# カレントディレクトリ内のすべての .xls ファイルを取得
$xlsFiles = Get-ChildItem -Path .\*.xls
# 各 .xls ファイルに対して処理を実行
foreach ($file in $xlsFiles) {
$filePath = $file.FullName
$newFilePath = $filePath -replace "\.xls$", ".xlsx"
# ワークブックを開く
$workbook = $excel.Workbooks.Open($filePath)
# .xlsx 形式で保存
$workbook.SaveAs($newFilePath, 51) # 51 は .xlsx 形式を意味する
$workbook.Close()
}
# Excel アプリケーションを閉じる
$excel.Quit()
# COM オブジェクトのリリース
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel) | Out-Null
Remove-Variable excel
メモ帳を開き.batで保存する
# Excelファイルの移動
@echo off
REM File move
REM xlsフォルダが存在しない場合にのみ作成
if not exist "xlsx\" mkdir xlsx
REM .xlsファイルをxlsフォルダに移動
move /-Y *.xlsx .\xlsx\
exit