Using Word to write to a .csv file?

C

Chris Sharp

I've been unable to effectively use WSH to create a .csv file from within my
VBA project in Word. I wish to send the results of my text formfields,
either into a .csv file, or better, directly into an Excel spreadsheet where
results of the text formfields will fill the first ten columns, then start
over, filling the next row of ten and so on until all fields are processed.
Should I consider an ADO or DDE approach ? TIA for any help.

chris s.
 
J

Jezebel

CSV is just a text file, which you can write directly from VBA using
Open/Print/Close statements. Or you can create a reference to Excel (eg
using CreateObject) and put your data directly into the target worksheet.
You don't need ADO and you certainly don't want DDE.
 
M

Michael Bednarek

I've been unable to effectively use WSH to create a .csv file from within my
VBA project in Word. I wish to send the results of my text formfields,
either into a .csv file, or better, directly into an Excel spreadsheet where
results of the text formfields will fill the first ten columns, then start
over, filling the next row of ten and so on until all fields are processed.
Should I consider an ADO or DDE approach ? TIA for any help.

chris s.

A CSV file is the simplest of structures for numbers; I'm not sure how well
text items can be dealt with, given that all conceivable delimiters might
occur in the text.

Assuming that the text doesn't contain quotes, the simplest method seems to
me to use fundamental BASIC methods:
Skeleton:

Dim strOut As String
Dim i As Long
Open "fu.bar" For Output As 1#
strOut = ""
For i = 1 To 10
strOut = strOut & """" & ActiveDocument.FormFields(i).Result & ""","
Next i
Print #1, strOut
Close #1
 

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