PC Review


Reply
Thread Tools Rate Thread

Add Column Names to VBA script

 
 
Joe K.
Guest
Posts: n/a
 
      6th Dec 2007

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

 
Reply With Quote
 
 
 
 
Dave D-C
Guest
Posts: n/a
 
      7th Dec 2007
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

Joe K. <Joe K.@discussions.microsoft.com> wrote:
>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.
>
>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


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create range names with names in column heading NigelVII Microsoft Excel Programming 2 29th Jul 2008 11:53 AM
Retrieving Excel Sheet Names/Column Names Rohit Microsoft ADO .NET 6 6th Dec 2005 01:59 PM
CHANGE COLUMN NAMES TO DEFINED NAMES =?Utf-8?B?RGF2aWQgQCBFbGl0ZQ==?= Microsoft Excel Misc 1 5th Oct 2004 04:29 PM
Change names of files in a folder to match names in Excel Column saybut Microsoft Excel Programming 4 9th Feb 2004 06:26 PM
Determine table names and column names in Access database Brian O'Haire Microsoft C# .NET 2 7th Dec 2003 01:28 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:34 PM.