Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 213
Default Importing multiple files


I borrowed a majority of this code from this NG and modified (read destroyed)
it for my needs, now I can't figure what I did wrong.
The macro should import a text file starting in A1, get the last row +1
(counting in column B) and repeat untill all files in the folder are
processed. The only cloumns that should have data are A thru H, row count
will vary.

Initially it appears to work, then the macro starts moving data to other
columns, like taking A1 thru A867 (A thru H) and moving it to I thru P and so
on and adding blank rows from the top down?

Code:
Sub aaa()
'Set Folder path
    Folder = "C:\MEASURE-6000\OUTPUT\Test\"

    'Create worksheet "Input"
    With ThisWorkbook
        Set InputSht = Worksheets.Add( _
                       after:=.Sheets(.Sheets.Count))
        InputSht.Name = "Input"
    End With
    'File name Extension to find
    FName = Dir(Folder & "*.OUT")

    Do While FName < ""
        'Input data file
        With InputSht
            'Count rows in column B
            InputShtLastRow = .Cells(Rows.Count, "B").End(xlUp).Row
            'MsgBox InputShtLastRow    'for testing

            'Add data to worksheet and append each new import
            With .QueryTables.Add( _
                 Connection:="TEXT;" & Folder & FName, _
                 Destination:=.Range("A" & InputShtLastRow + 1))

                .FieldNames = True
                .RowNumbers = False
                .FillAdjacentFormulas = False
                .PreserveFormatting = True
                .RefreshOnFileOpen = False
                .RefreshStyle = xlInsertDeleteCells
                .SavePassword = False
                .SaveData = True
                .AdjustColumnWidth = True
                .RefreshPeriod = 0
                .TextFilePromptOnRefresh = False
                .TextFilePlatform = xlWindows
                .TextFileStartRow = 1
                .TextFileParseType = xlDelimited
                .TextFileTextQualifier = xlTextQualifierDoubleQuote
                .TextFileConsecutiveDelimiter = True
                .TextFileTabDelimiter = True
                .TextFileSemicolonDelimiter = False
                .TextFileCommaDelimiter = True
                .TextFileSpaceDelimiter = True
                .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1)
                .Refresh BackgroundQuery:=False
            End With
        End With
    Loop
End Sub
Please help, I only have six or seven brain cells left!

--
Regards

XP Pro
Office 2003
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 213
Default Importing multiple files


I think I put myself in an endless loop with *Do While FName < ""*

--
Regards

XP Pro
Office 2003


"Rick S." wrote:

I borrowed a majority of this code from this NG and modified (read destroyed)
it for my needs, now I can't figure what I did wrong.
The macro should import a text file starting in A1, get the last row +1
(counting in column B) and repeat untill all files in the folder are
processed. The only cloumns that should have data are A thru H, row count
will vary.

Initially it appears to work, then the macro starts moving data to other
columns, like taking A1 thru A867 (A thru H) and moving it to I thru P and so
on and adding blank rows from the top down?

Code:
 Sub aaa()
 'Set Folder path
     Folder = "C:\MEASURE-6000\OUTPUT\Test\"
 
     'Create worksheet "Input"
     With ThisWorkbook
         Set InputSht = Worksheets.Add( _
                        after:=.Sheets(.Sheets.Count))
         InputSht.Name = "Input"
     End With
     'File name Extension to find
     FName = Dir(Folder & "*.OUT")
 
     Do While FName < ""
         'Input data file
         With InputSht
             'Count rows in column B
             InputShtLastRow = .Cells(Rows.Count, "B").End(xlUp).Row
             'MsgBox InputShtLastRow    'for testing
 
             'Add data to worksheet and append each new import
             With .QueryTables.Add( _
                  Connection:="TEXT;" & Folder & FName, _
                  Destination:=.Range("A" & InputShtLastRow + 1))
 
                 .FieldNames = True
                 .RowNumbers = False
                 .FillAdjacentFormulas = False
                 .PreserveFormatting = True
                 .RefreshOnFileOpen = False
                 .RefreshStyle = xlInsertDeleteCells
                 .SavePassword = False
                 .SaveData = True
                 .AdjustColumnWidth = True
                 .RefreshPeriod = 0
                 .TextFilePromptOnRefresh = False
                 .TextFilePlatform = xlWindows
                 .TextFileStartRow = 1
                 .TextFileParseType = xlDelimited
                 .TextFileTextQualifier = xlTextQualifierDoubleQuote
                 .TextFileConsecutiveDelimiter = True
                 .TextFileTabDelimiter = True
                 .TextFileSemicolonDelimiter = False
                 .TextFileCommaDelimiter = True
                 .TextFileSpaceDelimiter = True
                 .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1)
                 .Refresh BackgroundQuery:=False
             End With
         End With
     Loop
 End Sub

Please help, I only have six or seven brain cells left!

--
Regards

XP Pro
Office 2003

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Joel - Importing multiple text files to 1 spreadsheet, now importing from excel files Volker Hormuth Excel Programming 7 April 9th 09 06:55 PM
Importing multiple files Joel Excel Discussion (Misc queries) 0 February 19th 07 11:46 AM
Importing multiple files [email protected] Excel Programming 0 May 20th 06 07:06 PM
Importing multiple files schnett[_3_] Excel Programming 0 May 19th 06 05:09 PM
Importing Multiple files nearly there ianripping[_16_] Excel Programming 1 January 16th 04 01:01 AM


All times are GMT +1. The time now is 10:47 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"