I have a script that i thought would work to convert Excel (.xls) files to Excel 2007/2010 (.xlsx). However everytime i try to do the "saveas" I keep getting Exception calling "SaveAs" with "2" Argument(s): "SaveAs method of workbook class failed"
I have googled/binged and added the folder "Desktop" per one suggestion on my Windows 7 x64 running Office 2010 machine.
The script is below (some lines commented out as i was testing even tried changing to csv to see if it was my excel, with no luck)
#$xlFixedFormat = "Microsoft.Office.Interop.Excel.xlFixedFormatType" -as [type]
#$xlFixedFormat = xlWorkbookNormal
$xlFixedFormat = xlCSV
$excel = New-Object -ComObject excel.application
$excel.visible = $false
$folderpath = "C:\TEST\*"
$filetype ="*xls"
Get-ChildItem -Path $folderpath -Include $filetype |
ForEach-Object `
{
$path = ($_.fullname).substring(0,($_.FullName).lastindexOf("."))
"Converting $path to $filetype..."
$workbook = $excel.workbooks.open($_.fullname)
#$workbook.saveas($path,$xlFixedFormat::xlWorkbookDefault)
$workbook.saveas($path, $xlFixedFormat)
$workbook.close()
}
$excel.Quit()
$excel = $null
[gc]::collect()
[gc]::WaitForPendingFinalizers()