DataWriter

February 3, 2011

Downgrading an Excel File

Filed under: Scripting — Joe Casella @ 8:39 pm
Tags: , ,

Here’s a VBScript that will change an Excel 2007/2010 .xlsx file into an .xls or .csv file with a drag and drop:

  1. Dim fileName
  2. Dim oExcel
  3.  
  4.   fileName = WScript.Arguments(0)
  5.   newFileName = left(fileName, len(filename) -4)  & "xls"
  6. '* to save as CSV:  
  7. '* newFileName = left(FileName, len(fileName) -4) & "csv"  
  8.   set oExcel = CreateObject("Excel.Application")
  9.  
  10.     oExcel.Workbooks.Open fileName, False, True
  11.     oExcel.ActiveWorkbook.SaveAs newFileName,56   '* 56 = xExcel8
  12. '* to save as CSv:  
  13. '*'  oExcel.ActiveWorkbook.SaveAs newFileName, 6       
  14.     oExcel.ActiveWorkbook.Close False
  15.     oExcel.quit
  16.  
  17.   set oExcel = nothing

It’s a fast way to convert a file for email or an ETL process when you’re not already in Excel.

Theme: Rubric. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.