Created
May 3, 2011 22:36
-
-
Save gabceb/954418 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
$xlFixedFormat = [Microsoft.Office.Interop.Excel.XlFileFormat]::xlOpenXMLWorkbook | |
write-host $xlFixedFormat | |
$excel = New-Object -ComObject excel.application | |
$excel.visible = $true | |
$folderpath = "C:\Users\gabceb\Documents\testXLS" | |
$filetype ="*xls" | |
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() |
Thanks for the script!
I've done small modifications to make it work in 2021 (to solve aforementioned
SaveAs exception
issue). https://gist.github.com/RichMcLaren/096f3ee6bc23d35ed7730bbd36b33c44
That link seems dead, do you have another link to help get the saveas working?
That link seems dead, do you have another link to help get the saveas working?
@ace080 I've fixed the link in my original message now.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the script!
I've done small modifications to make it work in 2021 (to solve aforementioned
SaveAs exception
issue).https://gist.github.com/riskeez/096f3ee6bc23d35ed7730bbd36b33c44