Skip to content

Instantly share code, notes, and snippets.

Created July 25, 2013 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/36399497c667f3611c30 to your computer and use it in GitHub Desktop.
Save anonymous/36399497c667f3611c30 to your computer and use it in GitHub Desktop.
$object = New-Object -comObject Shell.Application
$folder = $object.BrowseForFolder(0, 'Select the folder', 0)
if (!$folder) {exit}
$excel = New-Object -comObject Excel.Application
$excel.Visible = $false
$excel.DisplayAlerts = $false
foreach ($file in Get-ChildItem -literalPath $folder.self.Path*.xls? -recurse) {
$workbook = $excel.Workbooks.Open($file.Fullname)
foreach ($worksheet in $workbook.Sheets) {
$worksheet.activate()
$newpath = $File.DirectoryName +"\"+ $file.BaseName + " - " + $worksheet.name + ".csv"
$workbook.SaveAs($newpath,-4158 ,$null,$null)
}
$workbook.Close()
}
$excel.quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($workbook)
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel)
[System.GC]::Collect()
[System.GC]::WaitForPendingFinalizers()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment