+ Reply to Thread
Results 1 to 4 of 4

opening an existing text file useing code

  1. #1
    ramki
    Guest

    opening an existing text file useing code

    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


  2. #2
    mark
    Guest

    RE: opening an existing text file useing code

    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




    "ramki" wrote:

    > 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
    >
    >


  3. #3
    Forum Contributor
    Join Date
    08-07-2004
    Location
    Ohio, USA
    Posts
    114
    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".

  4. #4
    ramki
    Guest

    Re: opening an existing text file useing code

    it is a plain text file which contains numbers seperated by tabs in the
    coulumns.


    give me a reply


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1