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.

Advertisements

1 Comment »

  1. Thanks for the code.

    Here is my 2 cent.
    Downgrade all files in a Folder.
    C#.
    Add COM excel reference.

    public void DowngradeTo2007(string RootExcelPath)
    {
    List fileList = Directory.GetFiles(RootExcelPath, “*.xlsx”).ToList();
    foreach (string file in fileList)
    {
    Microsoft.Office.Interop.Excel.Application objExcel = new Microsoft.Office.Interop.Excel.Application();
    Microsoft.Office.Interop.Excel.Workbook objBook = objExcel.Workbooks.Open(file);
    string xlsFile = Path.ChangeExtension(file,”xls”);
    objBook.SaveAs(xlsFile, 56);
    objBook.Close();
    objExcel.Quit();
    }

    }

    Comment by henrikbergstrom78 — August 11, 2013 @ 4:23 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: