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 / Word / Programming / November 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chris Moorhead - 29 Nov 2005 01:58 GMT
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!

cmoorhead@mindspring.com
Helmut Weber - 29 Nov 2005 20:13 GMT
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.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Chris Moorhead - 30 Nov 2005 01:02 GMT
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

>Hi Chris,
>
[quoted text clipped - 19 lines]
>whereever you want and destroy all of the file system,
>but that wasn't what you were asking for, I guess.
Doug Robbins - Word MVP - 30 Nov 2005 05:24 GMT
How about mail merge?

Signature

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

> 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
[quoted text clipped - 27 lines]
>>whereever you want and destroy all of the file system,
>>but that wasn't what you were asking for, I guess.
Graham Mayor - 30 Nov 2005 06:39 GMT
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

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> 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
[quoted text clipped - 27 lines]
>> whereever you want and destroy all of the file system,
>> but that wasn't what you were asking for, I guess.
Helmut Weber - 30 Nov 2005 08:41 GMT
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
Chris Moorhead - 30 Nov 2005 13:35 GMT
Thanks Helmut!

I'll give it a try.

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

......Chris

>Hi Chris,
>assumed you call the first paragraph in a csv-file a header,
[quoted text clipped - 19 lines]
>"red.sys" & chr(64) & "t-online.de"
>Word 2002, Windows 2000
Chris Moorhead - 30 Nov 2005 13:37 GMT
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

>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
[quoted text clipped - 29 lines]
>    ActiveDocument.Close
>End Sub

Rate this thread:






 
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.