Results 1 to 2 of 2

Edit Text file import code

Threaded View

  1. #1
    Registered User
    Join Date
    01-10-2012
    Location
    colorado, usa
    MS-Off Ver
    Excel 2010
    Posts
    41

    Edit Text file import code

    Hello,

    This is a mix of code that one forum member referred me to on Jerry Beaucaires website as well as some i've tried pathetically to incorporate by recording a macro while imported a text file. Jerry's code worked to put each text file onto a seperate sheet in one work book, but perhaps to my lack of experience it didn't seperate it out into rows and columns like it does when you use the import wizard. Any help is much appreciated, I try not to trouble the forum unless I really can't find the answer anywhere else. Thanks in advance to any contributors.

    Bryan




    Option Explicit
    
    
    
    Sub ImportCSVs()
    'Author:    Jerry Beaucaire
    'Date:      8/16/2010
    'Summary:   Import all CSV files from a folder into separate sheets
    '           named for the CSV filenames
    
    Dim fPath   As String
    Dim fTXT    As String
    Dim wbTXT   As Workbook
    
    fPath = "C:\Users\Bryan\Desktop\KP DHMO PROJECT\DHMO ROLL FILES\NCAL HB Accounts from WQ\04.04.2012\"           'path to CSV files, include the final \
    Application.ScreenUpdating = False  'speed up macro
    
    fTXT = Dir(fPath & "*.TXT")         'start the CSV file listing
    Sub CSVIMPORT()
    '
    ' CSVIMPORT Macro
    '
    
    '
        ChDir _
            "C:\Users\Bryan\Desktop\KP DHMO PROJECT\DHMO ROLL FILES\NCAL HB Accounts from WQ\04.04.2012"
        Workbooks.OpenText Filename:= _
            "C:\Users\Bryan\Desktop\KP DHMO PROJECT\DHMO ROLL FILES\NCAL HB Accounts from WQ\04.04.2012\NCAL HB CA 943.txt" _
            , Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
            xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False _
            , Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
            Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), _
            Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1), Array(14, 1), Array(15 _
            , 1), Array(16, 1), Array(17, 1), Array(18, 1), Array(19, 1), Array(20, 1), Array(21, 1), _
            Array(22, 1), Array(23, 1), Array(24, 1), Array(25, 1), Array(26, 1), Array(27, 1), Array( _
            28, 1), Array(29, 1), Array(30, 1), Array(31, 1), Array(32, 1), Array(33, 1)), _
            TrailingMinusNumbers:=True
    End Sub
    
        Do While Len(fTXT) > 0
            Set wbTXT = Workbooks.Open(fPath & fTXT)  'open a CSV file and move
            ActiveSheet.Move After:=ThisWorkbook.Sheets(Sheets.Count)
           
            fTXT = Dir                  'ready next CSV
        Loop
      
    Application.ScreenUpdating = True
    Set wbTXT = Nothing
    End Sub
    Last edited by Richard Buttrey; 04-09-2012 at 01:30 PM.
    STOP! CONTINENTAL DRIFT.

Thread Information

Users Browsing this Thread

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

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