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

C

Chris Moorhead

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!

(e-mail address removed)
 
H

Helmut Weber

Hi Chris,
Can anyone tell me how or provide a sample vb script that will read a
csv text file and write it to a new file

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.
without the end of file character ?

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"
 
C

Chris Moorhead

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
 
D

Doug Robbins - Word MVP

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
 
G

Graham Mayor

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
H

Helmut Weber

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
 
C

Chris Moorhead

Thanks Helmut!

I'll give it a try.

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

.......Chris
 
C

Chris Moorhead

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top