-
-
Save riskeez/096f3ee6bc23d35ed7730bbd36b33c44 to your computer and use it in GitHub Desktop.
Powershell script to convert all xls documents to xlsx in a folder recursively
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# XLS to XLSX Batch convert script | |
# Forked from https://gist.github.com/gabceb/954418 | |
# Works well using Office 365 | |
$folderpath = "D:\XLS Files" | |
$filetype ="*xls" | |
Add-Type -AssemblyName Microsoft.Office.Interop.Excel | |
$xlFixedFormat = [Microsoft.Office.Interop.Excel.XlFileFormat]::xlWorkbookDefault | |
write-host $xlFixedFormat | |
$excel = New-Object -ComObject excel.application | |
$excel.visible = $true | |
Get-ChildItem -Path $folderpath -Include $filetype -recurse | | |
ForEach-Object ` | |
{ | |
$path = ($_.fullname).substring(0, ($_.FullName).lastindexOf(".")) | |
"Converting $path" | |
$workbook = $excel.workbooks.open($_.fullname) | |
$path += ".xlsx" | |
$workbook.saveas($path, $xlFixedFormat) | |
$workbook.close() | |
$oldFolder = $path.substring(0, $path.lastIndexOf("\")) + "\old" | |
write-host $oldFolder | |
if(-not (test-path $oldFolder)) | |
{ | |
new-item $oldFolder -type directory | |
} | |
move-item $_.fullname $oldFolder | |
} | |
$excel.Quit() | |
$excel = $null | |
[gc]::collect() | |
[gc]::WaitForPendingFinalizers() |
Ignore my comment above. I could get past the pop-up by adding this:
$excel.DisplayAlerts = $False
-Madhuri Dara
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank You so much for the script.
The powershell script converts to xlsx but it has a pop-up message (Message Attached)
How can I say Continue Saving as a Macro-Free workbook?
Thank You,
Madhuri Dara