Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Write Heading in excel
#8
Solved: 11 Years, 3 Months, 3 Weeks ago
Hi Anu,
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
Reply


Messages In This Thread
Write Heading in excel - by Anu - 07-01-2010, 06:13 PM
RE: Write Heading in excel - by sreekanth chilam - 07-01-2010, 11:10 PM
RE: Write Heading in excel - by Anu - 07-12-2010, 01:37 PM
RE: Write Heading in excel - by basanth27 - 07-13-2010, 09:56 AM
RE: Write Heading in excel - by Anu - 07-13-2010, 02:34 PM
RE: Write Heading in excel - by sasmitakumari - 07-13-2010, 02:58 PM
RE: Write Heading in excel - by Anu - 07-26-2010, 11:40 AM
RE: Write Heading in excel - by sasmitakumari - 07-26-2010, 05:24 PM
RE: Write Heading in excel - by Anu - 07-26-2010, 05:35 PM
RE: Write Heading in excel - by sasmitakumari - 07-26-2010, 07:14 PM
RE: Write Heading in excel - by Anu - 07-27-2010, 11:13 AM
RE: Write Heading in excel - by sasmitakumari - 07-27-2010, 11:27 AM
RE: Write Heading in excel - by Anu - 07-27-2010, 12:02 PM
RE: Write Heading in excel - by sasmitakumari - 07-27-2010, 12:15 PM
RE: Write Heading in excel - by Anu - 07-27-2010, 12:27 PM
RE: Write Heading in excel - by sasmitakumari - 07-27-2010, 01:01 PM
RE: Write Heading in excel - by Anu - 07-27-2010, 01:55 PM
RE: Write Heading in excel - by sasmitakumari - 07-27-2010, 02:20 PM
RE: Write Heading in excel - by Anu - 07-27-2010, 02:23 PM
RE: Write Heading in excel - by sasmitakumari - 07-27-2010, 02:55 PM
RE: Write Heading in excel - by Anu - 07-27-2010, 05:55 PM
RE: Write Heading in excel - by sasmitakumari - 07-27-2010, 08:21 PM
RE: Write Heading in excel - by Anu - 07-28-2010, 10:34 AM
RE: Write Heading in excel - by Anu - 07-30-2010, 11:46 AM
RE: Write Heading in excel - by sreekanth chilam - 07-30-2010, 03:33 PM
RE: Write Heading in excel - by MVChowdary - 07-30-2010, 07:23 PM
RE: Write Heading in excel - by Anu - 08-03-2010, 10:37 AM
RE: Write Heading in excel - by Anu - 08-05-2010, 03:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Write in Excel Continued Anu 3 3,315 08-27-2010, 08:53 AM
Last Post: basanth27
  Write in Excel Anu 48 31,557 08-25-2010, 06:08 PM
Last Post: Saket

Forum Jump:


Users browsing this thread: 1 Guest(s)