Advertisement
Merzavets

re-save all XL files in proper frmt (c) Dmitry Sotnikov

Sep 16th, 2013
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ############################
  2.  # PowerShell script to open all Excel files in a folder
  3.  # and re-save them in proper format
  4.  # (c) Dmitry Sotnikov
  5.  ############################
  6.  
  7. # create COM object to use Excel
  8.  $objExcel = new-object -comobject excel.application
  9.  
  10. $objExcel.Visible = $True
  11.  
  12. # open the files to re-save one by one
  13.  dir D:\myfolder\*.xls | ForEach-Object {
  14.  $doc = $objExcel.WorkBooks.Open($_.FullName)
  15.  
  16. # Save in new format and with new extension
  17.  # Format codes can be found here:
  18.  # http://msdn.microsoft.com/en-us/library/office/ff198017.aspx
  19.  $doc.SaveAs(“$($_.Directory)\$($_.BaseName).xlsx”,
  20.  [Microsoft.Office.Interop.Excel.XlFileFormat]::xlOpenXMLWorkbook)
  21.  $doc.close()
  22.  }
  23.  
  24. $objExcel.Quit()
  25.  $objExcel = $null
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement