opening an existing text file useing code

  • Thread starter Thread starter ramki
  • Start date Start date
R

ramki

hay any one help me in opening an existing txt files with a macro or
VBA coding.

like i have differrent txt files in differrent file if open those file
each txt file will be opened in one excel but i want all of them to be
opened in the same excel file but in differrent sheets.

and one more thing if we open a text file in excel it will ask us for
the coulumn and row breaks i want to skip that as my default delimitar
is a space

thank you
 
I think you have to open them separately, but after you open the second one,
just move it the same workbook as the first.

The last line in this code performs the move:

Sub sbTwoTextFiles()

'dimension variables

Dim wsDest As Worksheet


'open first text file

Workbooks.OpenText Filename:="C:\text1.txt", StartRow:=1, _
DataType:=xlDelimited, ConsecutiveDelimiter _
:=False, Tab:=False, Semicolon:=False, Comma:=False, Space:=True


'set worksheet variable to first text sheet

Set wsDest = ActiveSheet


'open second text file

Workbooks.OpenText Filename:="C:\text2.txt", StartRow:=1, _
DataType:=xlDelimited, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=True


'move text file to sheet after first text file

ActiveSheet.Move After:=wsDest

End Sub
 
What kind of text file?
Flat ascii (all of the records and fields run together), CSV (comma
separated values -- not necessarily commas, it could be tabs, periods,
quotes, etc.) or some other format?

It matters because it determines the options you have to import data
into Excel. Whereas text files have to be "imported".
 
it is a plain text file which contains numbers seperated by tabs in the
coulumns.


give me a reply
 

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

Back
Top