07-26-2010, 05:24 PM
(This post was last modified: 07-26-2010, 05:26 PM by sasmitakumari.)
Hi Anu,
You need to save the file to see the result after run.
Try this out.
You need to save the file to see the result after run.
Try this out.
Code:
Dim sHeader, sHeaderList
Dim ExcelSheet
Dim sPath,sDataFile
Dim FSO, bFileFlag,sMyFile
Dim objExcel,i
sHeader = "Name,Address,ID"
sPath = "C:\"
sDataFile = "DataFile.xls"
Set FSO = CreateObject("Scripting.FileSystemObject")
bFileFlag = FSO.FileExists(sPath & sDataFile)
If(Not bFileFlag) Then
Set sMyFile = FSO.CreateTextFile (sPath & sDataFile, True, False)
sMyFile.Close
Set FSO = Nothing
End If
Set objExcel = CreateObject ("Excel.Application")
objExcel.DisplayAlerts = False
Set ExcelSheet = CreateObject("Excel.Sheet")
' Make Excel visible through the Application object.
ExcelSheet.Application.Visible = True
'*** Writing Header***'
sHeaderList = Split(sHeader, ",")
i = 0
For Each sHeader in sHeaderList
i = i + 1
ExcelSheet.ActiveSheet.Cells(1, i).Value = sHeader
Next
' Save the sheet.
ExcelSheet.SaveAs "C:\DataFile.xls"
' Close Excel with the Quit method on the Application object.
ExcelSheet.Application.Quit
' Release the object variable.
Set ExcelSheet = Nothing
Set objExcel = Nothing