Read csv text file and write to new file stripping header and end f file char

Read csv text file and write to new file stripping header and end f file char

Post by Chris Moor » Wed, 30 Nov 2005 10:58:36


All,

Can anyone tell me hoe or provide a sample vb script that will read a
csv text file and write it to a new file without the header and the
end of file character ?

TIA!

XXXX@XXXXX.COM
 
 
 

Read csv text file and write to new file stripping header and end f file char

Post by Helmut Web » Thu, 01 Dec 2005 05:13:27

Hi Chris,


as far as I know, CSV-files are simple text-files
which contain no header, unless you'd simply define
the first paragraph or line as a header.


I don't know, whether nowadays there is an
end-of-file character anymore.
Seems to me, that the last chr(13) in a file
once was called end-of-file character.

Try to delete the last paragraph mark in Word!
No way.

As this is the beginners' group,
it is possible to write any sequence of bytes
whereever you want and destroy all of the file system,
but that wasn't what you were asking for, I guess.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

 
 
 

Read csv text file and write to new file stripping header and end f file char

Post by Chris Moor » Thu, 01 Dec 2005 10:02:42

The CSV file is exported from Excel and the header is necessary so the
file can be examined for accuracy. Once examined I would like a vb
script that will open the file, read the file, and write the file to a
new location without the header.......or the EOF CHAR that I see with
my text editor.


..........Chris

On Tue, 29 Nov 2005 21:13:27 +0100, Helmut Weber
 
 
 

Read csv text file and write to new file stripping header and end f file char

Post by Doug Robbi » Thu, 01 Dec 2005 14:24:51

How about mail merge?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
 
 

Read csv text file and write to new file stripping header and end f file char

Post by Graham May » Thu, 01 Dec 2005 15:39:02

The end of file character is a function of your text editor. It is not
present in a CSV file exported from Excel when opened in many applications
including Word for which this is a forum.

You can open the file, strip the header and save the file to a new location
with something like that below, which opens the CSV document
c:\path\filename.csv uses replace to remove the first line (the header) then
saves it as a CSV file at d:\path\fielname.csv. Change the path and
filenames to protect the innocent.

Sub StripHeader()
ChangeFileOpenDirectory "C:\path\"
Documents.Open FileName:="""Filename.csv""", ConfirmConversions:=False _
, Format:=wdOpenFormatAuto, Encoding:=1252
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "*^13"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute replace:=wdReplaceOne
ActiveDocument.SaveAs FileName:="""D:\path\filename.csv"""
ActiveDocument.Close
End Sub

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://www.yqcomputer.com/
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
 
 

Read csv text file and write to new file stripping header and end f file char

Post by Helmut Web » Thu, 01 Dec 2005 17:41:14

Hi Chris,
assumed you call the first paragraph in a csv-file a header,
like this, and in many other ways:

Sub Makro1()
Dim sTmp As String
Open "c:\test\excel\test-inp.csv" For Input As #1
Open "c:\test\excel\test-out.csv" For Output As #2
' read first paragraph,
' but don't print to new file
Input #1, sTmp
While Not EOF(1)
Input #1, sTmp
Print #2, sTmp
Wend
Close #1
Close #2
End Sub

Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
 
 

Read csv text file and write to new file stripping header and end f file char

Post by Chris Moor » Thu, 01 Dec 2005 22:35:03

Thanks Helmut!

I'll give it a try.

My appologies for posting in this Word VBA forum.....

......Chris

On 30 Nov 2005 00:41:14 -0800, "Helmut Weber" < XXXX@XXXXX.COM >
 
 
 

Read csv text file and write to new file stripping header and end f file char

Post by Chris Moor » Thu, 01 Dec 2005 22:37:45

Thanks Graham!

I must appologize for not recognizing this was a Word VBA
forum.......I am trying to build a stand alone vbscript for this task.

.......Chris

On Wed, 30 Nov 2005 08:39:02 +0200, "Graham Mayor" < XXXX@XXXXX.COM >