Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / December 2007

Tip: Looking for answers? Try searching our database.

Add Column Names to VBA script

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joe K. - 06 Dec 2007 21:39 GMT
Please help me modify the script listed below to add the column names listed
beow to the first row in the test.csv file.  These column names are different
from the input worksheet.

Please help me complete this task.

Thanks,

Column Names
1. Caller_Id
2. MT_Port
3. Noy_Number
4. Scheduled_Date_ETP
5. Tship
6. Parcel_Quantity

Sub WriteCSV()

Const Delimiter = ","
Const MyPath = "C:\temp\"
   
Set fswrite = CreateObject("Scripting.FileSystemObject")
   
WriteFileName = "text.csv"

  'open files
  WritePathName = MyPath + WriteFileName
  fswrite.CreateTextFile WritePathName
  Set fwrite = fswrite.GetFile(WritePathName)
  Set tswrite = fwrite.OpenAsTextStream(ForWriting, TristateUseDefault)

  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
 
  For RowCount = 10 To LastRow
     If Range("D" & RowCount) > Date Then
        For ColCount = 1 To 6
           If ColCount = 1 Then
              OutputLine = Cells(RowCount, ColCount)
           Else
              OutputLine = OutputLine & Delimiter & Cells(RowCount, ColCount)
           End If
        Next ColCount
        tswrite.writeline OutputLine
     End If
  Next RowCount
     
  tswrite.Close
 
End Sub
Dave D-C - 07 Dec 2007 01:51 GMT
Unless the names are in cells somewhere, it looks like
they have to be in code:

OutputLine = "Caller_Id" & Delimiter & _
 "MT_Port" & Delimiter & _
 "Noy_Number" & Delimiter & _
 "Scheduled_Date_ETP" & Delimiter & _
 "Tship" & Delimiter & _
 "Parcel_Quantity"
  tswrite.writeline OutputLine
 
>Please help me modify the script listed below to add the column names listed
>beow to the first row in the test.csv file.  These column names are different
[quoted text clipped - 41 lines]
>  
>End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.