Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 2 of 2

Thread: open multiple files question

  1. #1
    New Member
    Join Date
    Feb 2002
    Posts
    28
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I want to open multiple files from a specific directoy in excel, with the following code every file is opened as a seperate workbook.
    My question is is it possible to do this from within a workbook so that every file found isn't opened as a workbook but as a new sheet in the workbook where i ran this code

    Sub Macro1()

    Set fs = Application.FileSearch
    With fs
    .LookIn = "C:Mijn documenten"
    .FileName = "*.txt"
    If .Execute > 0 Then
    MsgBox "Er zijn " & .FoundFiles.Count & _
    " files found."
    For i = 1 To .FoundFiles.Count
    MsgBox .FoundFiles(i)
    Workbooks.Open FileName:=.FoundFiles(i)
    Next i
    Else
    MsgBox "no files found."
    End If
    End With

    End Sub

  2. #2
    MrExcel MVP Ivan F Moala's Avatar
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    4,209
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    What you will have to do within the loop
    is to;
    After opening the file Copy over all the
    sheets then close the file.
    Then do the same with the next Workbook
    opened.

    Turn your macro recorder on and see what you get...incorporate the code into your code.
    Post back if any problems.
    Kind Regards,
    Ivan F Moala From the City of Sails

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
  •