ramlicious Blogs by Tina & Prabhu

July 5, 2011

VBScript to read an Excel file

Filed under: Scripting — Prabhuram @ 7:54 am

Here is a small program that will just use VBScript to read an excel file:

Const ForWriting = 2
Folder = "C:\Users\Prabhuram\Desktop\"
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open( Folder + "Applications.xls")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile (Folder + "Out-File.txt", ForWriting, True)
For Each mySheet In objWorkbook.Worksheets
  Set myRng = mySheet.UsedRange
  For Each myCell In myRng.Cells
    objTextFile.WriteLine(cstr(myCell.Value))
  Next
Next
objWorkbook.close
objTextFile.Close

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

You must be logged in to post a comment.

Powered by WordPress