Monday, January 28, 2008

Program to copy data from MS excel to a text file at particular location using VBScript

Dim objExcel, objFile, objFSO, objFolder
strFolder = "\\10.6.2.58\Waves\Documents\TeamInformation\Eshwari"
strFile = "\datafromexcel.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder(strFolder)
Set objFile = objFSO.CreateTextFile(strFolder & strFile)
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("W:\Documents\TeamInformation\BirthdayInfo.xls")
intRow = 2
Do Until objExcel.Cells(intRow,1).Value = ""
objFile.Write(objExcel.Cells(intRow, 1).Value & " ")
objFile.WriteLine(objExcel.Cells(intRow, 2).Value)
intRow = intRow + 1
Loop
objFile.Close
objExcel.Quit

No comments: