define, by code, separator fields when merging a textfile with a document

F

frank

I have a .doc document. I must merge it with a text file that contains some
data fields.
These data fields in the text file are separated by tab and the records
using ";"
Is there any way to define which separators I want to use in each case , by
code?

Thanks in advance.
Frank.
 
J

Jezebel

You'll need to explain this question more clearly. You want to pull the data
from the text file and insert it into the document. Your question seems to
be, how to parse the lines of the text file, given that they are delimited
with semi-colons?

You can use the Split() function to break a delimited string into fields,
with whatever delimiter sequence you choose:

Dim pFreeFile as long
Dim pLines() as string
Dim pFields() as string
Dim pLine as long

pFreeFile = FreeFile
Open MyFile.txt for input as #pFreeFile
pLines = split(input(LOF(pFreeFile),pFreeFile), vbCR)
close #pFreeFile

For pLine = lbound(pLines) to ubound(pLines)
pFields = split(pLines(pLine), ";")
:
Next


If this is a mailmerge task, another approach is to open the file in Excel
(which allows you to use any delimiter), save as a worksheet, then use that
file as your merge data source.
 
C

Cindy M -WordMVP-

Hi Frank,
I have a .doc document. I must merge it with a text file that contains some
data fields.
These data fields in the text file are separated by tab and the records
using ";"
Is there any way to define which separators I want to use in each case , by
code?
No, there is not. If you don't use a Chr(13) (or in combination with a
Chr(10) as the RECORD delimiter, you're going to get that dialog box. There's
no way to set the delimiters in VBA.

If your problem is that the data could contain "paragraph marks" (that's how
Word interprets them), then you need to place the data in "quotes" so that
it's clear to Word what's data, and what's not.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
Top