Quantcast
Channel: Import Text File Macro Help
Viewing all articles
Browse latest Browse all 2

Import Text File Macro Help

$
0
0

I need to know what is the best way to import this file into excel. I have a text file that has 46 rows however I only need rows 1, and row 17-46. The problem is I have to do a fixed with import when importing the file into excel  and the width to get what I need from row 1 is different from the width for rows 17-46. So what I did was I wrote a macro to set the width at what I need to get the data from row 1 which imports all 46 rows, then I wrote a macro starting the import at row 17 and set it at the width that gives me the data that I need to get from rows 17-46. Is there a way that I can combine these two macros so that I can get the data that I need from row 1 delete that data from rows 2-46 then apply the second macro on that same file and get rows 17-46 using the fixed width written in the second macro?

Here are the two macros VBA Code:

Sub Macro3()
'
' Macro3 Macro
'

'
    With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;\\HOUIC-NA-V504\josiah.morgan$\Cached\My Documents\Study RR47_2005\R1205001\R1205001rr.txt" _
        , Destination:=Range("$B$6"))
        .Name = "R1205001rr"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 437
        .TextFileStartRow = 1
        .TextFileParseType = xlFixedWidth
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(9, 1)
        .TextFileFixedColumnWidths = Array(25)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
End Sub

Sub Macro5()
'
' Macro5 Macro
'

'
    With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;\\HOUIC-NA-V504\josiah.morgan$\Cached\My Documents\Study RR47_2005\R1205001\R1205001rr.txt" _
        , Destination:=Range("$B$8"))
        .Name = "R1205001rr"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 437
        .TextFileStartRow = 17
        .TextFileParseType = xlFixedWidth
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(9, 1)
        .TextFileFixedColumnWidths = Array(29)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
End Sub


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images