Excel: VBA: import multiple csv files into their own worksheets

sluggo050499
sluggo050499 used Ask the Experts™
on
I'm building a macro to pull information from multiple worksheets.  The source of the data for each sheet is a csv file.  I will be building a form where the user can browse and import the csv files.  How can I write the VBA to pull File1.csv file into Worksheet1, File2.csv file into Worksheet2, File3.csv into Worksheet3, etc.  in a single VBA event?  (The names were just examples).

Please include code.
Thanks,
Doug
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Sub ImportCSV()

    Dim oCSV As Workbook
   
    Set oCSV = Workbooks.Open("C:\My Documents\11111.csv")
    oCSV.Sheets(1).Copy ThisWorkbook.Worksheets(1)
    oCSV.Close False
   
    Set oCSV = Workbooks.Open("C:\My Documents\22222.csv")
    oCSV.Sheets(1).Copy ThisWorkbook.Worksheets(1)
    oCSV.Close False
   
    Set oCSV = Workbooks.Open("C:\My Documents\33333.csv")
    oCSV.Sheets(1).Copy ThisWorkbook.Worksheets(1)
    oCSV.Close False
   
    Set oCSV = Nothing

End Sub
is there not a way I could open csv files but we do it from the file dialog bog, so I will select 3 files in the folder view then it will copy them to to the active workbook in a new tab each?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial