Results 1 to 3 of 3

Import all csv files in folder to sheet1

Threaded View

  1. #1
    Registered User
    Join Date
    09-13-2012
    Location
    FL
    MS-Off Ver
    Excel 365
    Posts
    21

    Import all csv files in folder to sheet1

    Good morning,

    I am having a problem with my macro. It seems to import all the csv files in, but they paste in sporadic places instead of just column A. I like the way the msoFileDialogFilePicker and InitialView are working, just cant get the array right.

    Any advice?? Thank you!

        Sub ImportCSV()
        Dim Str1 As String
        Dim i As Integer
        Dim fd As FileDialog
        Dim FileChosen As Integer
        Dim FileName As String
        Dim j As Long
        Dim Boo1 As Boolean
    
        'With Application.FileDialog(msoFileDialogFilePicker)
        
        Set fd = Application.FileDialog(msoFileDialogFilePicker)
            fd.InitialFileName = "N:\Folder\Files\2015\"
        fd.InitialView = msoFileDialogViewList
        
    
        With fd
            .AllowMultiSelect = True
                .Filters.Clear
                .Filters.Add "Comma delemited file (*.csv)", "*.csv"
                .Filters.Add "Text files (*.txt)", "*.txt"
                .Filters.Add "All Files (*.*)", "*.*"
             FileChosen = fd.Show
            'fd.Show
            
        If .SelectedItems.Count > 0 Then
        
        Worksheets(1).Activate
            
           
     j = 1
    For i = 1 To .SelectedItems.Count
        Str1 = "TEXT;" & .SelectedItems.Item(i)
        With ActiveSheet.QueryTables.Add(Connection:=Str1, Destination:=Cells(j, 1))
        .TextFileSemicolonDelimiter = True
        .Refresh BackgroundQuery:=False
        End With
        Boo1 = False
        While Boo1 = False
            j = j + 1
            If Cells(j, i).Value = "" Then
                Boo1 = True
            End If
        Wend
        
        Next
        
        End If
        
        End With
        
        
        End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Import values from other files in folder
    By nteil in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-05-2013, 09:33 AM
  2. Import row from a folder with .csv files
    By kbka in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-02-2013, 12:38 PM
  3. Noob 4 Help - Macro to LIST ALL FILES IN FOLDER and then IMPORT ALL LISTED FILES
    By StlSmiln in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-25-2012, 04:02 AM
  4. How to import two .txt files into sheet1, both on column D consecutively
    By zeroJames in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-19-2011, 11:25 AM
  5. Looking for VBA code to import data from two csv files into Excel sheet1 and sheet2 b
    By faizumarali in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-22-2010, 02:18 PM
  6. Replies: 1
    Last Post: 01-24-2006, 11:35 AM
  7. Replies: 1
    Last Post: 01-24-2006, 11:00 AM
  8. Replies: 1
    Last Post: 01-24-2006, 12:25 AM

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