View Full Version : VBA to copy .txt file

02-05-2008, 07:03 PM
Hi all,http://www.mrexcel.com/forum/images/smilies/icon_smile.gif

Can any one help me out with my requirement.

i have a txt file which system generates automatically daily.

1) i will download the .txt file, copy the contents, paste it into the excelsheet then delimit the contents.

2)downloaded contents contains headers like INDEXING, REVIEWING and ERRORS. All i need to do is copy the contents under INDEXING and paste it to an already existing saved excel file in the sheet naed index...
similarly for reviewing and errors.. and the values will not be constant and also volumes.

i am not sure whether this can be done using macros. This, i was doing manually and if i get a coding for this it will be highly helpful.:help

Thanks in advance !!!!


02-05-2008, 08:39 PM
Howdy. I changed the thread title to make it more specific to your needs.

02-05-2008, 10:24 PM
Yes, it can all be done automatically.

I'd be happy to help you if you give it a shot first.

First see if you can grab the data using a web query. I've also never tried to read an text file directly from a web address using filesystemobject. Wonder if that can be done.

Once you have the data file in Excel, then do Record Macro and parse your data. Stop recording the Macro. Examine the coding. Can you understand it? Can you apply it to this problem in the future when there's a new text file?

Anyways, I'd start with the web query.

Good luck!

02-06-2008, 05:03 AM

see if this thread helps you...


02-09-2008, 09:00 PM
Hi All,

I have attached the sample file.
The bolded ones in Sheet1 is to be copied to the concern tabs...


02-11-2008, 06:20 PM
Hi All,

Please help me out in this...


02-12-2008, 06:36 AM
i tried something like this (not totally automatic) for your first 2 items. the 3rd item doesn't quite work (are you needing only 2 columns from this?)

copy your data only, without the headings into a Sheet2 and run this

Option Explicit

Sub TrimXcessSpaces()
'Macro Purpose: To trim all excess spaces out of cells. This
'eliminates issues where users have cleared the cell with a space,
'and elimates all extra spaces at the beginning or end of a string

Dim cl As Variant

'Loop through cells removing excess spaces
For Each cl In Selection
If Len(cl) > Len(WorksheetFunction.Trim(cl)) Then
cl.Value = WorksheetFunction.Trim(cl)
End If
Next cl
End Sub

Perform a TextToColumns -->Delimited--> Delimiters :Other (type in a Space),
then copy & paste the resulting data into your designated sheet. there is coding that can be done but i'm not the best of candidates to write that.

repeat code as needed for your other data...

the coding Sub TrimXcessSpaces is courtesy of Ken Puls over here:

i believe that coding can be done up front to extract the data from your text file