exporting data to the middle of a text file

S

sba

Is it possible to write excel data to the *middle* of a text file? The
only writing/exporting I can find seems to either append the data to
the end, or overwrite the text file starting at the beginning (erasing
the existing text).

Woudl it work to rewrite the text file into a new name up to the
designated point, append the relevant excel cells at that position,
then continue rewriting the original text file into the new file? Not
sure I'm allowed to have files open for reading and writing at the
same time. And since my text file has 10,000's of lines, seems rather
slow and clunky to have to rewrite that many lines just to add a few
words.

I'm not new to programming, but rather new to excel/VBA. Thanks ahead
of time for any suggestions.
 
S

Steve Yandl

I'd investigate the object, "Scripting.FileSystemObject" that has methods
for opening text files for either reading, writing or appending. You don't
say how you will determine the insertion point so I can't provide too many
specifics. I suspect you will open your text file for reading and assign
the text stream before the break to one string variable and the text stream
after to a second variable and read your workbook cells into a third (or
multiple) variables, close the text file, open it again, this time for
writing and overwrite the previous contents with the content of your string
variables.

Steve Yandl
 

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