+ Reply to Thread
Results 1 to 30 of 30

importing multiple csv files into single workbook

Hybrid View

  1. #1
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: importing multiple csv files into single workbook

    My fault, it should be:

    Sub LoopFiles()
        Dim strDir As String, strFileName As String
        Dim wbSourceBook As Workbook
        Dim wbWriteBook As Workbook
        Dim wsWriteSheet As Worksheet
    
        strDir = "C:\"      'specify folder to search
        strFileName = Dir(strDir & "*.csv")
    
        Set wbWriteBook = Workbooks.Add
    
        Do While strFileName <> ""
            Set wbSourceBook = Workbooks.Open(strDir & strFileName)
            Set wsWriteSheet = wbWriteBook.Sheets.Add
            wsWriteSheet.Name = strFileName
            wbSourceBook.Sheets(1).UsedRange.Copy wsWriteSheet.Range("A1")
            wbSourceBook.Close False
            strFileName = Dir
        Loop
    
    End Sub

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  2. #2
    Registered User
    Join Date
    05-24-2012
    Location
    Greenville, SC
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: importing multiple csv files into single workbook

    I changed this line strFileName = Dir(strDir & "*.csv")

    to a .txt extension to import a folder full of txt files. It's only creating a new workbook but it comes out empty. Any help on why this doesn't work?

    ---------------------------------------------------------------------------------
    DISREGARD. I got it to work; it was blocking the macro due to computer settings. thanks
    Last edited by gtparce; 05-24-2012 at 01:40 PM. Reason: Solved Problem

  3. #3
    Registered User
    Join Date
    06-14-2012
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: importing multiple csv files into single workbook

    Hello,

    Brand new to the forum. This macro looks perfect for me but I have the same problems as above. A new blank worksheet is produced. I don't know anything about unblocking macro's so was hoping for a little guidance if possible please?

    Cheers

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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