Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: Importing Multiple txt files using a macro: how?

  1. #1
    Board Regular
    Join Date
    Mar 2002
    Location
    Aberdeen, Scotland
    Posts
    72
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I'm trying to write a generic open command in vba which opens all files with a particular file extension in a particular folder.

    the best i can come up with so far is:

    workbooks.opentext filename:= "C:Test" & "*" & ".txt" [etc.]

    the only bit which doesn't work is the "*" bit. The macro runs but, only opens the "first" file in the folder, not all of them.

    Anyone got any ideas?

    Cheers,

    Dave

    [ This Message was edited by: Puma on 2002-04-22 03:51 ]

    [ This Message was edited by: Puma on 2002-04-22 03:51 ]

  2. #2
    Board Regular
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    6,824
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi Dave,

    Sub OpenTextFiles()
    Dim Fs, i
    Set Fs = Application.FileSearch

    With Fs
    .LookIn = "C:Test"
    .Filename = "*.txt"
    If .Execute Then
    For i = 1 To .FoundFiles.Count
    Workbooks.OpenText Filename:=.FoundFiles(i)
    Next
    End If
    End With
    End Sub

    Cheers back at yu!

    Tom

  3. #3
    Board Regular
    Join Date
    Mar 2002
    Location
    Aberdeen, Scotland
    Posts
    72
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Cheers!!

    worked a treat.



    Dave

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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